如何将图像名称保存在数据库中以便以后查看?

在注册用户时,他输入了一张照片,并且管理员可以在管理区域中查看这张照片


网页.php


Route::post('/head', 'ImageController@upload')->name('image.upload');

图像控制器.php


namespace App\Http\Controllers;


use Illuminate\Http\Request;


class ImageController extends Controller

{

    public function upload(Request $request)

    {

        $path = $request - file('image')->store('upload', 'public');

        return view('default',['path'=> $path]);

    }

}

(php artisan storage:link)输入


输入表格


<div class="form-group row">

    <label for="ydostak" class="col-md-4 col-form-label text-md-right">{{ __('Фото удостоверение с двух сторон') }}</label>

    <form action{{ route('image.upload')}}="" method="post" accept-charset="multipart/form-data">

        {{ csrf_field() }}


        <div class="form-group">

            <input type="file" name="image">

        </div>

    </form>

</div>

提款表


@isset ($path)

    <img class="img-fluid" scr="{{asset('/storage/'. $path)}}" alt="">

@endisset


桃花长相依
浏览 106回答 2
2回答

跃然一笑

&nbsp;public function upload(Request $request){&nbsp; &nbsp; $user&nbsp; = new user ;&nbsp; &nbsp; if($request->hasFile('image')){&nbsp; &nbsp; &nbsp; $image = $request->file('image');&nbsp; &nbsp; &nbsp; $filename = time() . '.' . $image->getClientOriginalExtension();&nbsp; &nbsp; &nbsp; Image::make($image)->resize(300, 300)->save( storage_path('/uploads/' . $filename ) );&nbsp; &nbsp; &nbsp; $user->image = $filename;&nbsp; &nbsp; &nbsp; $user->save();&nbsp; &nbsp; };&nbsp; $user->save();&nbsp; return redirect()->route('user.index')&nbsp; &nbsp; ->with('success','User created successfully');&nbsp; &nbsp;}

长风秋雁

您的表单标签格式不正确:<form&nbsp;action{{&nbsp;route('image.upload')}}=""&nbsp;method="post"&nbsp;accept-charset="multipart/form-data">你没有为你分配任何东西,action因为你拥有的不是action属性。你有这样的事情:<form&nbsp;actionhttp://yoursite/head=""&nbsp;...>这不是action属性。你要:<form&nbsp;action="{{&nbsp;route('image.upload')&nbsp;}}"&nbsp;...>这会给你类似的东西:<form&nbsp;action="http://youriste/head"&nbsp;...>一旦你解决了这个问题,你就可以开始实际处理你的 Controller 方法。
打开App,查看更多内容
随时随地看视频慕课网APP