0

ā€œI’m setting up a new image and it saved in the database,but when i try to show the image i have an "Undefined variable" ErrorException

web.php

Route::post('/leftAdv','LeftBannerController@store');
Route::get('/leftAdv','LeftBannerController@leftAdv');

//this is the contoller LeftBannerController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\LeftSideBanner;

 class LeftBannerController extends Controller
{
public function leftAdv()
{
    return view('adminAdv.leftAdv');
}
public function store(Request $request)
{
   $this->validate(request(),[


        'left_banner_url'=>'image|mimes:jpg,jpeg,png,gif,jfif',

            ]);

   $img_name=time() .'.' . $request->left_banner_url->getClientOriginalExtension();


    $LeftSideBanner= new LeftSideBanner;
    $LeftSideBanner->left_banner_url=$img_name;
    $LeftSideBanner->link=request('link');
    $LeftSideBanner->save();


    $request->left_banner_url->move(public_path('photos'),$img_name);

    return redirect('/posts');
   }
 }

//this is the form leftAdv.blade.php

      {{ csrf_field() }}

    <div class="form-group">
        <label for="left_banner_url">Image</label>
        <input type="file" name="left_banner_url" id="left_banner_url">
    </div>
    <div class="form-group">
        <label for="link">Link</label>
        <input type="text" name="link" id="link" class="form-control">
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-primary">Add Post</button>
    </div>

    <div style="color:red;">
        @foreach ($errors->all() as $error)
        {{ $error }} <br>
        @endforeach
    </div>
   </form>

//this where iam trying to show the imag

    <img src"photos/{{$LeftSideBanner->left_banner_url }}"
  • Because you are redirecting after your query but not sending the data to the view, So get the data from where you are redirecting – BlackXero Aug 09 '19 at 11:57
  • it seems not the solution because if i redirect to leftAdv it stays on the same page and didnt show the image. – salim bahouth Aug 11 '19 at 08:56

0 Answers0