laravel-5.2

Laravel 5.2 validation errors not appearing

只愿长相守 提交于 2019-12-02 01:08:42
I am trying to get validation errors to show up in Laravel. I have a UserController set up like so: <?php namespace App\Http\Controllers; use App\User; use App\Http\Controllers\Controller; //Use Request; Use Flash; Use Illuminate\Http\Request; class UserController extends Controller { /** * Show the profile for the given user. * * @param int $id * @return Response */ public function showProfile($id) { return view('user.profile', ['user' => User::findOrFail($id)]); } public function store(Request $request) { $this->validate($request, [ 'email' => 'required|unique:users|email|max:255', ]); if(

Laravel Associate method is returning empty array in the view

左心房为你撑大大i 提交于 2019-12-02 00:45:37
I am working on a simple social network, i am working on the replies section now. I associated the post/status model with user as below, but when i tried to access in the view it returns empty array [] . Reply function in Post Model public function postReply(Request $request, $statusId){ $this->validate($request, [ "reply-{$statusId}" => 'required|max:1000', ], [ 'required' => 'The reply body is required' ] ); $post = Post::notReply()->find($statusId); if(!$post){ return redirect('/'); } if(!Auth::user()->isFriendsWith($post->user) && Auth::user()->id !== $post->user->id){ return redirect('/')

Laravel get Eloquent relation by same name as its attribute

China☆狼群 提交于 2019-12-01 23:47:43
问题 I have database tables like this: shoot: id, name, programme programme: id, name The eloquent relationship in the shoot is defined like this: public function programme() { return $this->belongsTo('App\Programme', 'programme', 'id'); } When using dd() , I can see this is working correctly: dd(Shoot:where('id','=',1)->with('programme')->first()); // prints the object with programme listed under the relationship However when I eager-load the shoot and attempt to get the programme object, I

Laravel get Eloquent relation by same name as its attribute

心已入冬 提交于 2019-12-01 23:35:27
I have database tables like this: shoot: id, name, programme programme: id, name The eloquent relationship in the shoot is defined like this: public function programme() { return $this->belongsTo('App\Programme', 'programme', 'id'); } When using dd() , I can see this is working correctly: dd(Shoot:where('id','=',1)->with('programme')->first()); // prints the object with programme listed under the relationship However when I eager-load the shoot and attempt to get the programme object, I retrieve the shoot attribute "programme" instead. E.g.: $shoot = Shoot:where('id','=',1)->with('programme')-

How to set language for Carbon?

删除回忆录丶 提交于 2019-12-01 20:15:08
So i want to set language for Carbon, but i always get same result. Carbon::setLocale('es'); $archive_current_year = Articles::whereBetween('created_at', [ Carbon::now()->startOfYear(), Carbon::now()->endOfYear(), ])->get()->groupBy(function($item) { return $item->created_at->format('F'); }); try using PHP function setlocale also check if your hosting allows and gives you the locales you want. setlocale(LC_TIME, 'es_ES'); Carbon::setLocale('es'); $archive_current_year = Articles::whereBetween('created_at', [ .... Carbon is actually using the php setlocale(); . The Carbon::setLocale('es')

Laravel Access denied for user 'root'@'localhost' (using password: YES) in laravel 4.2

丶灬走出姿态 提交于 2019-12-01 17:45:32
I have old project which built using Laravel 4.2.I am getting following error PDOException (1045) SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) I have googled and tried every think but i couldn't able to fix it .env file APP_KEY=az9tq5VHQCV9g5m2CsgY89jtijrCMgEA DB_HOST=localhost DB_DATABASE=billing DB_USERNAME=root DB_PASSWORD=1234 database.php 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'billing', 'username' => 'root', 'password' => '1234', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ), Can any

TokenMismatchException for API in Laravel 5.2.31

时光总嘲笑我的痴心妄想 提交于 2019-12-01 17:45:17
What Am I trying? I already have a website and I am trying Token based authentication for an API in same code and below is the start for sample authentication code I created a controller below is the code. class AccountController extends \App\Http\Controllers\Controller { public function apilogin($UserData) { return json_decode($UserData); } } My route config is below. Route::group(['prefix' => 'api/v1', 'middleware' => 'auth.api'], function () { Route::post('/apilogin', 'API\User\Account\AccountController@apilogin'); }); **Then from the Postman Chrome Extension, I have posted the request and

Batch insert in Laravel 5.2

白昼怎懂夜的黑 提交于 2019-12-01 15:41:53
I am using a API's with lot's of calculation almost 100 database fields at the end with a big Foreach loop. In every iteration i insert data in database. I want to insert data in once at the end (Batch Insert like in CodeIgniter). Any body have idea how to insert all data at the end of iteration. instead of every iteration it insert row in database. I want to insert data at the end of loop. Any help or idea appreciated. Use insert() method for bulk insertion. First, build an array with this structure: $data = [ ['name' => 'John', 'age' => 25], ['name' => 'Maria', 'age' => 31], ['name' =>

Session data not preserved after redirection

大城市里の小女人 提交于 2019-12-01 15:34:02
I'm trying to implement some custom flash messages and I'm having some issues with the session data being destroyed after a redirect. Here's how I create my flash messages : flash('Your topic has been created.'); Here's the declaration of the flash() function : function flash($message, $title = 'Info', $type = 'info') { session()->flash('flash', [ 'message' => $message, 'title' => $title, 'type' => $type, ]); } And here is how I'm checking the session/displaying the flash messages, using SweetAlerts. This code is included at the bottom of the main layout file that I'm extending in all my Blade

Batch insert in Laravel 5.2

梦想与她 提交于 2019-12-01 14:24:50
问题 I am using a API's with lot's of calculation almost 100 database fields at the end with a big Foreach loop. In every iteration i insert data in database. I want to insert data in once at the end (Batch Insert like in CodeIgniter). Any body have idea how to insert all data at the end of iteration. instead of every iteration it insert row in database. I want to insert data at the end of loop. Any help or idea appreciated. 回答1: Use insert() method for bulk insertion. First, build an array with