app/Http/Controllers/ArticlesController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
      $this->validate($request,[
      'name'=>'required',
      'cijena'=>'required',
      'kolicina'=>'required',
      'opis'=>'required'
      ]);
      if($request->hasFile('slika'))
      {
        $fileNameWithExt = $request->file('slika')->getClientOriginalName();
        $filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
        $extension = $request->file('slika')->getClientOriginalExtension();
        $fileNameToStore = $filename.'_'.time().'.'.$extension;
        $path = $request->file('slika')->storeAs('public/slike',$fileNameToStore);
      }
      $article = Article::find($id);
      $article->name = $request->input('name');
      $article->cijena = $request->input('cijena');
      $article->kolicina = $request->input('kolicina');
      $article->category_id = $request->input('category_id');
      $article->opis = $request->input('opis');
      if($request->hasFile('slika')){
        $article->slika=$fileNameToStore;
      }
      $article->save();
      return redirect('/articles')->with('success', 'Artikl uspješno uređen');
    }
public function update ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'name' => 'required' , 'cijena' => 'required' , 'kolicina' => 'required' , 'opis' => 'required' ] ) ; if ( $ request -> hasFile ( 'slika' ) ) { $ fileNameWithExt = $ request -> file ( 'slika' ) -> getClientOriginalName ( ) ; $ filename = pathinfo ( $ fileNameWithExt , PATHINFO_FILENAME ) ; $ extension = $ request -> file ( 'slika' ) -> getClientOriginalExtension ( ) ; $ fileNameToStore = $ filename . '_' . time ( ) . '.' . $ extension ; $ path = $ request -> file ( 'slika' ) -> storeAs ( 'public/slike' , $ fileNameToStore ) ; } $ article = Article :: find ( $ id ) ; $ article -> name = $ request -> input ( 'name' ) ; $ article -> cijena = $ request -> input ( 'cijena' ) ; $ article -> kolicina = $ request -> input ( 'kolicina' ) ; $ article -> category_id = $ request -> input ( 'category_id' ) ; $ article -> opis = $ request -> input ( 'opis' ) ; if ( $ request -> hasFile ( 'slika' ) ) { $ article -> slika = $ fileNameToStore ; } $ article -> save ( ) ; return redirect ( '/articles' ) -> with ( 'success' , 'Artikl uspješno uređen'); }
Update the specified resource in storage.
Update the specified resource in storage .
//Za sliku //Dohvaćanje filename-a sa extenzijom //Dohvati samo $fileName //dohvati samo ekstenziju //Ime za pohranu //Upload slike