laravel-5.2

How to disable chunked encoding for JSON responses in Laravel?

烈酒焚心 提交于 2019-12-11 00:05:59
问题 I'm returning an array from a controller method in Laravel. Laravel interprets this to mean I want to send JSON, which is great, but it doesn't set the Content-Length and instead uses Transfer-Encoding: chunked . My responses are tiny, so I don't want to chunk them. How can I disable chunked encoding + enable Content-Length? I'm using nginx for the server, if relevant. 回答1: My solution is adding content-length headers to the response, then chunked-transfer will be replaced $responseJson =

Split results into 5 columns

我们两清 提交于 2019-12-10 23:45:29
问题 I have a query like: $results = Post::all(); For the sake of simplicity, let's say the output is this (by id ): 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 My website has a 5-column layout. I need to split/divide these results into 5 columns such that it ends up like this: 1 | 2 | 3 | 4 | 5 6 | 7 | 8 | 9 | 10 11 | 12 | 13 | 14 | 15 The 5 column layout is split like this (the total number of columns is 25): <div class="row"> <div class="col-xs-5"> // </div> <div class="col-xs-5"> // <

Laravel 5.2 Auth::login not persisting logged user

被刻印的时光 ゝ 提交于 2019-12-10 23:26:50
问题 I have an authentication system which has also social login using Socialite. The problem is when I use Auth::login() to log in the user when successfully authenticated from social media, the session doesn't persist after redirecting. Though I am using the web middleware here is my code in routes.php Route::group(['namespace' => 'Frontend', 'middleware' => 'web'], function () { Route::get('/', 'PagesController@index'); Route::get('login/{provider?}', 'AuthController@getLogin'); Route::post(

Laravel 5.2 Pretty URLs

时光毁灭记忆、已成空白 提交于 2019-12-10 23:01:51
问题 How can i change http://domain.com/public/index.php to http://domain.com and can get the other routes working other than ('/') ? Workaround 1: vhost file: <VirtualHost *:80> DocumentRoot "/var/www/html/domain/public" ServerName domain.com <Directory "/var/www/html/domain/public"> AllowOverride All Allow from All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> htaccess file: <IfModule mod_rewrite.c> <IfModule mod_negotiation.c>

Laravel 5 | Interface 'Illuminate\Contracts\Routing\Middleware' not found

我怕爱的太早我们不能终老 提交于 2019-12-10 22:38:32
问题 I use Laravel 5. I try, "use Illuminate\Contracts\Routing\Middleware;" to implement "Middleware" as, class Language implements Middleware { // Some Functions } I Get Error as, Interface 'Illuminate\Contracts\Routing\Middleware' not found Is actually that interface is Missing ? (OR) Mistake in defining ? (OR) Need to Create | Download ? Thank Q ! 回答1: The Illuminate\Contracts\Routing\Middleware contract has been deprecated in 5.2, remove it. And dont use it in class definition. Like this <?php

ON DUPLICATE KEY UPDATE in Eloquent

天涯浪子 提交于 2019-12-10 21:23:56
问题 I just started laravel and all I want to do is get following query working in Eloquent : INSERT INTO geschichte (geschichte_id, geschichte_text1, geschichte_text2, geschichte_text3) VALUES (:geschichte_id, :geschichte_text1, :geschichte_text2, :geschichte_text3) ON DUPLICATE KEY UPDATE geschichte_id = :geschichte_id, geschichte_text1 = :geschichte_text1, geschichte_text2 = :geschichte_text2, geschichte_text3 = :geschichte_text3; Controller function public function alterGeschichte(Request

Laravel 5.2 Login Event Handling

别来无恙 提交于 2019-12-10 20:51:28
问题 In the database I have a table users with column last_login_at. Everytime when some user logs in - I want to uptade last_login_at . So, I created app/Listeners/ UpdateLastLoginOnLogin.php : namespace App\Listeners; use Carbon\Carbon; class UpdateLastLoginOnLogin { public function handle($user, $remember) { $user->last_login_at = Carbon::now(); $user->save(); } } In app/Providers/EventServiceProvider: protected $listen = [ 'auth.login' => [ 'App\Listeners\UpdateLastLoginOnLogin', ], ]; BUT

laravel 5.2 - search function

雨燕双飞 提交于 2019-12-10 19:55:15
问题 I wish to make a custom search on my site. Here is MySQL Search: SELECT * FROM MyDB . MyTable WHERE ( id LIKE '%MySearch%' OR firstname LIKE '%MySearch%' OR lastname LIKE '%MySearch%' OR email LIKE '%MySearch%' OR address LIKE '%MySearch%'); How can I get that search into my Laravel Controller?? $users = DB::table('MyTable')->where('firstname', 'MySearch')->get(); My Laravel Controller Thanks in advance ! 回答1: $users = DB::table('MyTable') ->where('id', 'LIKE', '%MySearch%') ->or_where(

pagination in laravel 5.3 when count of pages = 1

谁说我不能喝 提交于 2019-12-10 19:39:53
问题 I have cities table and it has 7 cities I have a view page to display these cities with 10 cities per page Controller: $cities = City::orderBy('id', 'desc')->paginate(10); return view('cities.home', compact('cities')); View: <div class="table-responsive panel panel-sky"> <table class="table table-striped table-hover"> <tr> <th>#</th> <th>Name</th> <th>Created At</th> <th>Action</th> </tr> @foreach($cities as $city) <tr id="product{{$city->id}}"> <td>{{$city->id}}</td> <td>{{$city->name}}</td>

Error column not found in Laravel

我是研究僧i 提交于 2019-12-10 19:31:18
问题 This is my forumthread table: $table->increments('id'); $table->integer('user_id')->unsigned(); $table->foreign( 'user_id' )->references( 'id' )->on( 'users' ); $table->string('thread'); $table->string('slug'); $table->dateTime('published_at'); And this is my forumindex table: $table->increments('id'); $table->integer('user_id')->unsigned(); $table->foreign( 'user_id' )->references( 'id' )->on( 'users' ); $table->integer('forumthreads_id')->unsigned(); $table->foreign( 'forumthreads_id' )-