app/Http/Controllers/ComicController.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(Request $request)
    {
        $request->validate([
            "title" => "required|string|max:150|unique:comics",
            "description" => "required|string",
            "thumb" => "required|url",
            "price" => "required|numeric|between:0,99999.99",
            "series" => "required|string|max:50",
            "sale_date" => "required|date",
            "type" => "required|string|max:20"
        ]);
        $data = $request->all();
        $newComic = new Comic();
        $newComic->title = $data["title"];
        $newComic->description = $data["description"];
        $newComic->thumb = $data["thumb"];
        $newComic->price = $data["price"];
        $newComic->series = $data["series"];
        $newComic->sale_date = $data["sale_date"];
        $newComic->type = $data["type"];
        $newComic->save();
        return redirect()->route('comics.show', $newComic->id);
    }
public function store ( Request $ request ) { $ request -> validate ( [ " title " => " required|string|max:150|unique:comics " , " description " => " required|string " , " thumb " => " required|url " , " price " => " required|numeric|between:0,99999.99 " , " series " => " required|string|max:50 " , " sale_date " => " required|date " , " type " => " required|string|max:20 " ] ) ; $ data = $ request -> all ( ) ; $ newComic = new Comic ( ) ; $ newComic -> title = $ data [ " title " ] ; $ newComic -> description = $ data [ " description " ] ; $ newComic -> thumb = $ data [ " thumb " ] ; $ newComic -> price = $ data [ " price " ] ; $ newComic -> series = $ data [ " series " ] ; $ newComic -> sale_date = $ data [ " sale_date " ] ; $ newComic -> type = $ data [ " type " ] ; $ newComic -> save ( ) ; return redirect ( ) -> route ( 'comics.show' , $ newComic -> id ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//Validazione //Inserisco in $data i dati della form //Creazione nuovo record