Plz share your RegisterController
Laravel built in auth with user image
Im using laravel built in auth system that can be found easily with running php artisan make:auth command in a new laravel project. While registering i would like to give the user, the ability to upload their profile picture too. So i have added a new field called profile_picture in the registration form. How do i receive the file from backend? I have tried adding the Request $request argument to the create method after array $data But it says-
Type error: Argument 1 passed to App\Http\Controllers\Auth\RegisterController::create() must be an instance of Illuminate\Http\Request, none given, called in /home/tawsif/laravel/repto_events/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php on line 33
====== namespace App\Http\Controllers\Auth;
use App\User; use Validator; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Http\Request;
class RegisterController extends Controller { use RegistersUsers;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
'profession' => 'required|min:3',
'phone' => 'required|digits:11',
'address' => 'required|min:5'
// 'profile_picture' => 'required|image'
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(Request $request, array $data )
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'phone' => $data['phone'],
'ssc_year' => $data['ssc'],
'hsc_year' => $data['hsc'],
'profession' => $data['profession'],
'address' => $data['address'],
]);
$file = $request->file('profile_picture');
$thumbnail_path = public_path('uploads/propic/thumbnail/');
$original_path = public_path('uploads/propic/original/');
$file_name = 'user_'. $user->id .'_'. str_rand(32) . '.' . $file->getClientOriginalExtension();
Image::make($file)
->resize(261,null,function ($constraint) {
$constraint->aspectRatio();
})
->save($original_path . $file_name)
->resize(90, 90)
->save($thumbnail_path . $file_name);
$user->update(['profile_picture' => $file_name]);
return $user;
}
}
Please or to participate in this conversation.