laravel-4

Laravel expire session on browser close not working in Chrome

蓝咒 提交于 2019-12-23 08:26:49
问题 I am using Laravel Framework version 4.1.21 and the "expire_on_close" option does not end the session in Chrome when the browser is closed. The options in my config/session.php file look like this: 'driver' => 'file', 'lifetime' => 120, 'expire_on_close' => true, Also in the developer toolbar, under Resources > Cookies, the Expires value is set to "Session" for the laravel_session cookie. This works fine in Firefox though. Any ideas what am I missing ? Thanks ! 回答1: It's becasue of Chrome's

Laravel : How to take last n(any number) rows after ordered in ascending order?

天大地大妈咪最大 提交于 2019-12-23 07:39:07
问题 I have 3 columns id , msg and created_at in my Model table. created_at is a timestamp and id is primary key. I also have 5 datas, world => time4 , hello => time2 , haha => time1 , hihio => time5 and dunno => time3 and these datas are arranged in ascending order (as arranged here) based on their id . In laravel 4, I want to fetch these data, arrange them in ascending order and take the last n(in this case, 3) number of records. So, I want to get dunno , world and hihio rows displayed like this

Route Model Binding and Soft Deletes - Laravel 4

喜夏-厌秋 提交于 2019-12-23 07:34:52
问题 When using soft deletes and route to model binding their arises a circumstance when you cannot view the injected model if it has been "soft deleted". e.g. I have a Job model. if i "trash" one of these models and then open the trash and try to view the Job model i get a 404 resource not found. I resolved this by using the Route::bind() function as such Route::bind('job', function($id, $route) { return Job::withTrashed()->find($id); }); although this seems unnecessary and a little silly... is

array_map and pass 2 arguments to the mapped function - array_map(): Argument #3 should be an array

馋奶兔 提交于 2019-12-23 06:56:27
问题 I have an abstract class that looks like this: abstract class Transformer { /** * Transform a collection of items * * @param array $items * @param bool $format * @return array */ public function transformCollection(array $items, $format) { return array_map([$this, 'transform'], $items, $format); } /** * Transform a item * * @param array $item * @param bool $format * @return mixed */ public abstract function transform(array $item, $format); } Then I have the following class that implements it:

array_map and pass 2 arguments to the mapped function - array_map(): Argument #3 should be an array

不羁岁月 提交于 2019-12-23 06:54:02
问题 I have an abstract class that looks like this: abstract class Transformer { /** * Transform a collection of items * * @param array $items * @param bool $format * @return array */ public function transformCollection(array $items, $format) { return array_map([$this, 'transform'], $items, $format); } /** * Transform a item * * @param array $item * @param bool $format * @return mixed */ public abstract function transform(array $item, $format); } Then I have the following class that implements it:

Laravel Eloquent how to use between operator

自闭症网瘾萝莉.ら 提交于 2019-12-23 06:47:10
问题 I am trying to find an elegant way in Eloquent and Laravel to say select * from UserTable where Age between X and Y Is there a between operator in Eloquent (I can't find it). The closest i have gotten so far is chainging my query like this $query->where(age, '>=', $ageFrom) ->where(age, '<=', $ageTo); I also came across whereRaw that seems to work $query->whereRaw('age BETWEEN ' . $ageFrom . ' AND ' . $ageTo . ''); Is there an actual Eloquent way (not raw) that deals with ranges? 回答1: $query-

laravel 4 handle not found in Route::model

假如想象 提交于 2019-12-23 05:47:04
问题 when use "Route::model" in routes.php Route::model('pizza', 'Pizza'); Route::get('edit/{pizza}', 'PizzaController@edit'); I receive error if "id" not found in DB, how to display custom message in this status? thanks, 回答1: By default, Laravel will throw a 404 error if the model binding fails. So what you'll want to do is provide a closure as a third parameter to override the behavior and throw a different error: Route::model('pizza', 'Pizza', function() { throw new ModelNotFoundException; //

Get query results for date range

≡放荡痞女 提交于 2019-12-23 05:29:25
问题 I have the following query: $input_datestart = date("Y-m-d", strtotime($data["date_start"])); $input_dateend = date("Y-m-d", strtotime($data["date_end"])); //Calculate the recurrent dates $query = $query->join('events_dates_recurrent', 'events.id', '=', 'events_dates_recurrent.event_id') ->whereRaw("ABS(DATEDIFF('" . $input_datestart . "', CAST(events_dates_recurrent.start_date AS DATE)) % events_dates_recurrent.repeat_interval) = 0"); For a single day, I get the desired result now, which is

All Laravel routes “not found” on nginx

雨燕双飞 提交于 2019-12-23 05:19:15
问题 Trying to setup Laravel 4.1 installation on a nginx server (first time) and I'm given "not found" for every Laravel route instead of the view expected. The main page loads fine. Please note, site can only be accessed by IP which is why I have the filler IP 123.123.123.123 for server_name . etc/nginx/nginx.conf: listen 80; user nginx; worker_processes 4; worker_rlimit_nofile 200000; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 4000; use epoll;

Visting a laravel project with localhost via apache

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 04:56:37
问题 I have just installed a laravel project into my Home/public_html folder. I gave it a name, let's call it laravel for this purpose. So the template installed to Home/public_html/laravel and then I ran a composer install . I got a database password error. I fixed that, ran it again, and all went well. I then created a migration, a controller, and a view. I tried to navigate to it via localhost/laravel/public/events (events is my created view) I get a 404. I remembered I needed a config file in