假設兩個 Model : A, B, 一對一關係,例如 A has B, B belongs A,當要撈出 A 中有 B 且符合 在 B 的篩選欄位條件。A 是 Post 貼文, B 是 Comment 評論,A 和 B 的更新日期時間欄位都是
read more假設兩個 Model : A, B, 一對一關係,例如 A has B, B belongs A,當要撈出 A 中有 B 且符合 在 B 的篩選欄位條件。A 是 Post 貼文, B 是 Comment 評論,A 和 B 的更新日期時間欄位都是
read moreRefer from link: http://laragems.com/post/a-quick-way-to-display-a-sql-query-in-tinker Please enter tinker command: php artisan tinker Type below code: DB::listen(function ($query) { dump($query->sql); dump($query->bindings); dump($query->time); }); And from above line on, every ORM manipulation you type will show what transformed SQL is.
read moreVersion: Laravel 5.5 Model: Post, Comment Post’s columns: id, title, content, created_at, updated_at Comment’s columns: id, post_id, content, c_date, c_time, u_date, u_time Relation: A post has many comments and a comment belongs to a post. The following shows how to get posts, which had been comments in recent 24 hours. use CarbonCarbon; // use package Post::whereHas('comments', function ($query) { $query->whereRaw('(u_date = ? AND u_time >= ?) OR (u_date =? AND
read moreLaravel 5.5 請用 composer 安裝 albertcht/invisible-recaptcha,安裝指令是 composer require albertcht/invisible-recaptcha ,設定 invisible recaptcha 的變數值在 .env 檔案,請參考這個網頁 https://github.com/albertcht/invisible-recaptcha Laravel controller 端
read moreWe can get session value or data of a loginned user at AppServiceProvider. The following we will show how to get, share values of session and loginned user to all views. ========= Code: namespace App\Yourapp\Younamespace; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Session; use Illuminate\Support\View; use App; class AppServiceProvider extends ServiceProvider{ public function boot() { $auth = $this->app['auth']; // get Laravel's Auth facades view()->composer('*', function($view) use (&$auth) { // this function coding style is
read morePHP 語言的開發框架 Laravel 5.5 從 controller 傳布林值變數到 blade.php 的方式如下: 假設我們從 controller 傳同名變數到 view blade 去 // controller 檔案 class ABCController { public function index(Request $request) { $isBooked = true; return view('home.landing_page', compact('isBooked')); } } // view blade 檔案的部份內
read more