我有2個登錄與不同的控制器/模型。對於contender_user 2 - for enterprise_user。 雖然它們看起來與企業用戶的文件完全相同,我不能達到enterprise_user的IDAuth :: user() - > id不會工作Laravel 5.2 /試圖獲取非對象的屬性
文件,沒有錯誤:
namespace App\Http\Controllers\contender_user; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Session; use Illuminate\Support\ServiceProvider; use App\Http\Requests; use App\Http\Controllers\Controller; use App\Models\contender_user; use Illuminate\Support\Facades\Auth; class contender_userController extends Controller { public function applications_contender_user_show() { return view('contender_user/applications'); } public function home_show() { $id = Auth::user()->id; $contender_user = new contender_user\contender_userModel(); $results = $contender_user->get_user_all($id); return view('contender_user/home', array ( 'name' => $results[0]->name, 'email' => $results[0]->email, 'created_at' => $results[0]->created_at )); } }
文件有錯誤: 行:$ ID = Auth :: user() - > id; 錯誤:試圖當我複製它還是對錯誤信息的工作文件,以獲得非對象
namespace App\Http\Controllers\enterprise_user; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Session; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Auth; use App\Http\Requests; use App\Http\Controllers\Controller; use App\Models\enterprise_user; class enterprise_userController extends Controller { public function applications_show() { return view('enterprise_user/applications'); } public function home_show() { $id = Auth::user()->id; $enterprise_user = new enterprise_user\enterprise_userModel(); $results = $enterprise_user->get_user_all($id); return view('enterprise_user/home', array ( 'name' => $results[0]->name, 'email' => $results[0]->email, 'created_at' => $results[0]->created_at ) ); }
的財產:(
請幫助
你使用任何警衛? –
在使用Auth :: user()之前檢查用戶會話是否存在(Auth :: check()) –
'$ id = Auth :: id();'也會有效。 – Chris