app/Http/Controllers/AdminPostsController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(PostsCreateRequest $request)
    {
        $input = $request->all();
        $input['user_id'] = Auth::user()->id;
        if($file = $request->file('photo_id')){
            $name = time() . $file->getClientOriginalName();
            $file->move('images', $name);
            TODO: add fields to Photo model that will let you know to which User or Post the photo belongs. 
            TODO: question yourself about this. 
            $photo = Photo::create(['file'=>$name]);
            $input['photo_id'] = $photo->id;
        }
        $user = Auth::user();
        $user->posts()->create($input);
        return redirect('/admin/posts');
    }
public function store ( PostsCreateRequest $ request ) { $ input = $ request -> all ( ) ; if ( $ file = $ request -> file ( 'photo_id' ) ) { $ name = time ( ) . $ file -> getClientOriginalName ( ) ; $ file -> move ( 'images' , $ name ) ; $ photo = Photo :: create ( [ 'file' => $ name ] ) ; $ input [ 'photo_id' ] = $ photo -> id ; } $ user = Auth :: user ( ) ; $ user -> posts ( ) -> create ( $ input ) ; return redirect ( '/admin/posts' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// //$input['user_id'] = Auth::user()->id; //TODO: add fields to Photo model that will let you know to which User or Post the photo belongs.  //TODO: question yourself about this. 