如何修复PHP Laravel中的“未定义变量”错误

时间:2019-08-09 11:48:48

标签: php laravel-5

“我正在设置一个新图像并将其保存在数据库中,但是当我尝试显示该图像时,我有一个“未定义的变量” ErrorException

web.php

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

//这是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');
   }
 }

//这是形式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>

//这是我试图展示imag的地方

    <img src"photos/{{$LeftSideBanner->left_banner_url }}"

0 个答案:

没有答案