久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

laravel-5.4 - 錯誤:從空值創建默認對象

laravel-5.4 - error :Creating default object from empty value(laravel-5.4 - 錯誤:從空值創建默認對象)
本文介紹了laravel-5.4 - 錯誤:從空值創建默認對象的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想在數據庫中存儲圖像路徑.vendorlaravelframeworksrcIlluminateFoundationAuthRegistersUsers.php 下的我的控制器代碼如下:

I want to store image path in database. My Controller code undervendorlaravelframeworksrcIlluminateFoundationAuthRegistersUsers.php follows:

public function register(Request $request)
{
    $this->validator($request->all())->validate();

    if($request->hasFile('image')) {
    $image_name = $request->file('image')->getClientOriginalName();              
    $image_path = $request->file('image')->store('public'); 
    $user->image = Storage::url($image_name);
    $user->save();
    }

    event(new Registered($user = $this->create($request->all())));

   // $this->guard()->login($user); disable autologin for new users

    return $this->registered($request, $user)
                    ?: redirect($this->redirectPath());
}

我收到以下錯誤:RegistersUsers.php 第 40 行中的 ErrorException:從空值創建默認對象 .

I am getting the following error: ErrorException in RegistersUsers.php line 40: Creating default object from empty value .

圖像正在保存在公共文件夾中,但無法將圖像路徑保存在用戶表數據庫中.用戶表的架構
Schema::create('users', function (Blueprint $table) {$table->increments('user_id');$table->string('name');$table->string('image');$table->rememberToken();$table->timestamps();

The image is getting saved in public folder but not able to save image path in the user table database. schema of user table
Schema::create('users', function (Blueprint $table) { $table->increments('user_id'); $table->string('name'); $table->string('image'); $table->rememberToken(); $table->timestamps();

如何將圖像路徑存儲在數據庫中的用戶表中

how to proceed to store the image path in the user table in database

推薦答案

你還沒有初始化變量 $user 所以在控制器中,在使用它之前你必須添加 $user = new User; 假設你已經有 use AppUser;

you haven't initialized the variable $user so in the controller and before using it you've to add $user = new User; assuming that you already have use AppUser;

$user = new AppUser; 如果你不這樣做.

or $user = new AppUser; if you don't.

更新如果您嘗試更新現有的用戶記錄,您必須通過根據應在請求中發送的主鍵進行選擇來初始化 $user 變量,然后進行如下初始化:

Update if you're trying to update an existing user record you've to initialize the $user variable by selecting based on it's primary key which should be sent in the request and then doing the initialization like:

$user_id = $request->input('user_id');
$user = User::find($user_id);

這篇關于laravel-5.4 - 錯誤:從空值創建默認對象的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

add new element in laravel collection object(在 Laravel 集合對象中添加新元素)
Creating an edit modal in Laravel 5(在 Laravel 5 中創建編輯模式)
Laravel 5.5 API resources for collections (standalone data)(用于集合的 Laravel 5.5 API 資源(獨立數據))
What is the best practice to create a custom helper function in php Laravel 5?(在 php Laravel 5 中創建自定義輔助函數的最佳實踐是什么?)
No #39;Access-Control-Allow-Origin#39; header - Laravel(沒有“Access-Control-Allow-Origin標頭 - Laravel)
Laravel Passport Route redirects to login page(Laravel Passport Route 重定向到登錄頁面)
主站蜘蛛池模板: 国产美女一区二区 | 国产精品一区二区视频 | www.色.com | 亚洲欧美在线观看 | 午夜影院在线观看 | 观看av | 日韩手机在线看片 | 久久草在线视频 | 亚洲婷婷六月天 | 国产美女一区 | 中文一级片| 日韩视频精品 | 久草精品视频 | 久久久毛片 | 在线成人免费av | 久久国内精品 | 中文字幕av在线播放 | 青青久久av北条麻妃海外网 | 欧美日在线| 天天干天天想 | 成人av在线大片 | 91在线视频 | av天天干| 色综合桃花网 | 久久久国产视频 | 五月天国产在线 | 久久久久国产成人精品亚洲午夜 | 亚洲一区二区三区在线 | 国产丝袜一区二区三区免费视频 | 草草草影院 | 欧美一级片 | 国产免费va | 欧美成人精品欧美一级 | 在线中文字幕第一页 | 在线日韩av电影 | 国产在线小视频 | 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 久久久2o19精品 | 精品欧美一区二区三区久久久 | 精品免费国产视频 | 国产高清一区二区 |