app/Http/Controllers/RecipeController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  Request  $request
     * @return Response
     */
Store a newly created resource in storage.
@param  Request  $request
@return Response
Store a newly created resource in storage . @param Request $request @return Response
public function store(Request $request)
    {
        $rules = array(
            'title' => 'required|string|min:2|max:100',
            'description' => 'max:200',
            'prep' => 'required|string|max:10',
            'cook' => 'required|string|max:10',
            'difficulty' => 'required',
            'serves' => 'required|integer',
            'ingredients' => 'required|string|min:2|max:10000',
            'preparation' => 'required|string|min:2|max:10000',
            'image' => 'required|file|image|max:5000'
        );        
        $this->validate($request, $rules);
        if ($request->hasFile('image')) {
            $path = $request->file('image')->store('images', 'public');
        } else $path = NULL;
        $recipe = Recipe::create([
            'title' => $request->title,
            'user_id' => Auth::User()->id,
            'description' => $request->description,
            'prep' => $request->prep,
            'cook' => $request->cook,
            'difficulty' => $request->difficulty,
            'serves' => $request->serves,
            'ingredients' => $request->ingredients,
            'preparation' => $request->preparation,
            'image' => $path,
        ]);
        return redirect()->action('RecipeController@show', $recipe->id);
    }
public function store ( Request $ request ) { $ rules = array ( 'title' => 'required|string|min:2|max:100' , 'description' => 'max:200' , 'prep' => 'required|string|max:10' , 'cook' => 'required|string|max:10' , 'difficulty' => 'required' , 'serves' => 'required|integer' , 'ingredients' => 'required|string|min:2|max:10000' , 'preparation' => 'required|string|min:2|max:10000' , 'image' => 'required|file|image|max:5000' ) ; $ this -> validate ( $ request , $ rules ) ; if ( $ request -> hasFile ( 'image' ) ) { $ path = $ request -> file ( 'image' ) -> store ( 'images' , 'public' ) ; } else $ path = NULL ; $ recipe = Recipe :: create ( [ 'title' => $ request -> title , 'user_id' => Auth :: User ( ) -> id , 'description' => $ request -> description , 'prep' => $ request -> prep , 'cook' => $ request -> cook , 'difficulty' => $ request -> difficulty , 'serves' => $ request -> serves , 'ingredients' => $ request -> ingredients , 'preparation' => $ request -> preparation , 'image' => $ path , ] ) ; return redirect ( ) -> action ( 'RecipeController@show' , $ recipe -> id ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .