Skip to main content

Posts

Showing posts from December, 2017

Get the last query executed in Laravel

Sometimes it's useful for debugging purposes to preview the query that Laravel generates with Eloquent/Fluent. Laravel 5 (!) In Laravel 5 you should enable do DB ::enableQueryLog() ;    first.Then after placing your final statement: DB ::table ( 'users' ) -> where ( 'name' , '=' , 'Aknavi' ) -> get(); just run: dd(DB::getQueryLog()); it will return the SQL and the bindings of the last queries that were executed. Laravel 4 In Laravel 4 queryLogging is enabled by default, so you should just do: dd(DB:: getQueryLog() ) ; Laravel 3 In Laravel 3 you can run DB ::last_query() ;    But you should have profiler enabled in application/config/database.php Or you can use the profiler to get all queries executed for the current request and their execution time.  

Laravel 5 task scheduling with cron job example

If you want to execute scheduling jobs in specific time and specific interval then you can apply cron job which is a Unix command. We can manage a task in the server that executes scripts which helps in sending daily/weekly reports from our website. The main use of cron job is in cleaningup the databases, sending the emails, executing the time consuming tasks etc. We can simply delete files from the database with the help of Cron Job. Cron job will only work on unix based machines. It consists of a configuration file called Crontable which is also known as Crontab. This Cron tab is used to manage the scheduling and consists of different cron jobs and each of the cron job is associated with a specific task. Generate A New Command Class : First, we will generate our own custom commands by running following commands which will generate a class in the app/Console/Commands/ directory. php artisan make:console CustomCommand After running this command you will get a me...