1
參考Laravel教程我開始創建Laravel應用,我看到一些導師寫的MySQL查詢控制器上可以在Laravel控制器上編寫MySQL查詢嗎?
如:
$user = new User();
$user->user_name = $input['user_name'];
$user->email = $input['email'];
$user->password = $input['password'];
$user->phone = $input['phone'];
$user->mobile = $input['mobile'];
$user->address = $input['address'];
$user->save();
例如2:
$data['count'] = DB::select("SELECT COUNT(*) AS user_count FROM users WHERE notification='1'");
它是確定在Laravel Controller上編寫這些所有查詢?請指教我
通常不會。查詢屬於你的數據庫交互層(存儲,模型,無論...)。附:這個問題在這裏是offtopic和適合https://programmers.stackexchange.com/更好 – JimiDini 2014-10-31 11:44:23
爲什麼你不使用[querybuilder](http://laravel.com/docs/4.2/queries)? – Jerodev 2014-10-31 12:02:41