duankuangxie9070 2016-11-21 19:40
浏览 56

Laravel Users表更新

the image show is my Users table structure in Laravel 5.2, Yellow marks indicate that this rows are containing data when I sign up from Laravel Default Authentication. Now I want to update empty rows. I have created profile.blade.php for using Post method and userController is coded with:

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

use App\Http\Requests;
use Auth;
use Image;

class UsersController extends Controller
{
    public function getsignup()
    {
        return view('edit_profile', array('user' => Auth::user()));
    }

    public function postsignup(Request $request)
    {
        //dd($request->all());         

        if($request->hasFile('img')){
            $img = $request->file('img');
            $file_name = time() . '.' . $img->getClientOriginalExtension();
            Image::make($img)->resize(300, 300)->save( public_path('/uploads/images/' . $file_name ));

        }
        $user = Auth::User();
        $user->img =$file_name;
        $user->city = 'city';
        $user->country = 'country';
        $user->company_name = 'comapany_name';
        $user->street_name = 'street_name';
        $user->apartment = 'apartment';
        $user->village = 'village';
        $user->city = 'city';
        $user->postal_code = 'postal_code';
        $user->post_office = 'post_office';
        $user->nid = 'nid';
        $user->phone = 'phone';

        $user->save();
        return back()->with('message', 'Successfully Registered!');
    }    
    }

enter image description here But its only taking such value like 'city', 'company_name', etc. As i provided second image. I got stuck. I am new in Laravel. I hope you have a solution for me. Thanks In advance.

enter image description here

  • 写回答

2条回答 默认 最新

  • douyan4470 2016-11-21 19:53
    关注

    why are the field updates inside the if condition? this way it will only update if an image was uploaded

    try this

    public function postsignup(Request $request)
        {
            //dd($request->all());
    
    
            if($request->hasFile('img')){
                $img = $request->file('img');
                $file_name = time() . '.' . $img->getClientOriginalExtension();
                Image::make($img)->resize(300, 300)->save( public_path('/uploads/images/' . $file_name ));
                $user->img =$file_name;
                }
    
    
            $user = Auth::User();
            $user->city = $s;
            $user->country = 'country';
            $user->company_name = 'comapany_name';
            $user->street_name = 'street_name';
            $user->apartment = 'apartment';
            $user->village = 'village';
            $user->city = 'city';
            $user->img = isset($user->img)? $user->img : '';
            $user->postal_code = 'postal_code';
            $user->post_office = 'post_office';
            $user->nid = 'nid';
            $user->phone = '
    
            $user->save();
            return back()->with('message', 'Successfully Registered!');
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗