I have created a method in my User model to upload a poster (with intervention)for the user:
/**
* Store user's poster.
*/
public static function storePoster(Request $request)
{
if($request->hasFile('posterUpload')){
$poster = $request->file('posterUpload');
$filename = time() . '.'. $poster->getClientOriginalExtension();
Image::make($poster)->resize(356,265)->save(public_path('/uploads/posters/'.$filename));
$check = Setting_user::where([
['user_id', '=' ,Auth::user()->id],
['setting_id','=', 2],
])->first();
if(!$check)
{
$setting = new Setting_user();
$setting->user_id = Auth::user()->id;
$setting->setting_id = 2;
$setting->value = $filename;
$setting->save();
return back();
}
$check->value = $filename;
$check->update();
return back();
}
}
In my UserController I have another method which call the static method created in the User model:
/**
* Store user's poster.
*/
public function poster(Request $request)
{
User::storePoster($request);
}
This is my route:
Route::post('/user-profile/store/poster', 'UserController@poster');
And this is the error I get when I navigate to "/user-profile/store/poster" :
Argument 1 passed to App\User::storePoster() must be an instance of App\Request, instance of Illuminate\Http\Request given, called in C:\xampp\htdocs\laravel\laravel-paper-dashboard\app\Http\Controllers\UserController.php on line 29 and defined
Although if I move all the logic from the model and put it in my UserController it works fine. Any idea why?
Thanks in advance.
You need to use the same request class in the controller and the model, so in you user model add use Illuminate\Http\Request
at the top of the class to tell it which Request class to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With