iyke's avatar
Level 1

upload user images

please how do i upload images on my registration form?

0 likes
3 replies
Khudadad's avatar

This is an example controller method and the rest is easy you can edit it

     public function store(NewsRequest $request)
{
    $news = new News();
    $news->title = $request->input('title');
    $news->body = $request->input('body');
    $slug = $request->input('title');
    $news->slug = str_replace(' ', '+', $slug);
    if($request->hasFile('image'))
    {
        $image = $request->file('image');
        $imageName = date('Y') . "_" . $image->getClientOriginalName();
        $distination_path = 'images/news/';
        $image->move($distination_path, $imageName);
        $news->photo = $distination_path . $imageName;
    }
    $news->user_id = \Auth::user()->id;
    $news->save();
    return redirect('news')->with('message','خبر موفقانه ثبت شد!')->with('errors','خطارخ داده');
}
afrar's avatar

I apologize of my poor English. pls create one mapper for picture and user whose fields will be as 'id', 'user_id' , 'picture_id' than create Picture modal whose fields will be 'id','picture_location', after user register you will get 'user_id' and after picture store you will get picture_id, store this both ids in mapper. and using relation get location of user pic.

Please or to participate in this conversation.