图像显示是Laravel 5.2中的Users
表结构,黄色标记表示当我从Laravel默认身份验证注册时,这些行包含数据。现在我想更新空行。我创建profile.blade.php
以使用Post
方法,userController
编码为:
<?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 但它只是采取了诸如“城市&#39;”,“公司名称”等等这样的价值。因为我提供了第二张图片。我被困。我是Laravel的新人。我希望你有一个解决方案。提前致谢。
答案 0 :(得分:0)
为什么if条件中的字段更新? 这样它只会在上传图像时更新
试试这个
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!');
}
答案 1 :(得分:0)
这完美有效:
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 = $request->city;
$user->country = $request->country;
$user->company_name = $request->comapany_name;
$user->street_name = $request->street_name;
$user->apartment = $request->apartment;
$user->village = $request->village;
$user->postal_code =$request ->postal_code;
$user->post_office =$request->post_office;
$user->nid = $request->nid;
$user->phone = $request->phone;
$user->save();
return back()->with('message', 'Successfully Registered!');
}