laravel-4

Function mcrypt_get_iv_size() is deprecated on Laravel 4

♀尐吖头ヾ 提交于 2019-12-31 21:26:33
问题 I am in L4, here is my app.php <?php return array( /* |-------------------------------------------------------------------------- | Application Debug Mode |-------------------------------------------------------------------------- | | When your application is in debug mode, detailed error messages with | stack traces will be shown on every error that occurs within your | application. If disabled, a simple generic error page is shown. | */ 'debug' => true, /* |---------------------------------

Laravel check for constraint violation

末鹿安然 提交于 2019-12-31 20:01:39
问题 I was curious if there is a way we can check if there is a constraint violation error when delete or insert a record into the database. The exception thrown is called 'QueryException' but this can be a wide range of errors. Would be nice if we can check in the exception what the specific error is. 回答1: You are looking for the 23000 Error code (Integrity Constraint Violation) . If you take a look at QueryException class, it extends from PDOException, so you can access to $errorInfo variable.

How do I implement Gravatar in Laravel?

只谈情不闲聊 提交于 2019-12-31 19:49:13
问题 What's the fastest way to implement Gravatar URLs in Laravel? I have a mandatory email address field, but I don't want to create a new column for Gravatars, and I'd prefer to use the native Auth::user() attributes. 回答1: Turns out, you can use a Laravel mutator to create attributes that don't exist in your model. Assuming you have a User model with a mandatory email column in the corresponding users table, just stick this in your User model: public function getGravatarAttribute() { $hash = md5

laravel migration re-organising column order

五迷三道 提交于 2019-12-31 17:51:16
问题 When you create a new column in a table you can use the ->after('column name') to dictate where it goes. How can I create a migration that re-orders the columns in the right order I want? 回答1: Try this, hope it help you to find right solution: public function up() { DB::statement("ALTER TABLE example MODIFY COLUMN foo DATE AFTER bar"); } public function down() { DB::statement("ALTER TABLE example MODIFY COLUMN foo DATE AFTER bar"); } 回答2: If you want to do it without destroying data, you

Render Blade from string instead of File

淺唱寂寞╮ 提交于 2019-12-31 17:11:48
问题 How can I render an string which contains blade syntax? View::make('directory.file-name')->with('var', $var); // Usual usage View::render('{{$var}}')->with('var', $var); // Like this for Example I use wrote an script that produces blade syntax and I want to give it's output directly to blade engine if possible. Thanks 回答1: Hope this helps, https://github.com/TerrePorter/StringBladeCompiler This is a fork of the next link that removes the db model requirement and replaces it with a array that

Laravel 4 how to display flash message in view?

喜夏-厌秋 提交于 2019-12-31 10:32:14
问题 I'm trying to get my flash message to display. This is in my routing file Route::post('users/groups/save', function(){ return Redirect::to('users/groups')->withInput()->with('success', 'Group Created Successfully.'); }); This is in my view {{ $success = Session::get('success') }} @if($success) <div class="alert-box success"> <h2>{{ $success }}</h2> </div> @endif But nothing is working. When I try this, I get an error Variable $success is undefined. But it actually shows the flash message too.

Including PHP files with Laravel framework

可紊 提交于 2019-12-31 09:11:32
问题 I am trying to "include" a php script into one of my views (landing.blade.php). The script is in: /laravel-master/public/assets/scripts/config.php When I try to include this code in the view: <?php include_once('/assets/scripts/config.php'); ?> I get the error: include_once(/assets/scripts/config.php): failed to open stream: No such file or directory This is on localhost using MAMP. I'm not sure if there is a different set of rules I need to use with Laravel 4 to include a php file. Thank you

Laravel 4 Controller Templating / Blade - Correct method? [closed]

戏子无情 提交于 2019-12-31 08:58:46
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I've been reading through the Laravel 4 documentation and have been making a demo application to help with learning. I couldn't find much documentation on the templating of views with blade and controllers. Which is the correct method or does it come down to personal

Laravel 4 Controller Templating / Blade - Correct method? [closed]

我怕爱的太早我们不能终老 提交于 2019-12-31 08:58:31
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I've been reading through the Laravel 4 documentation and have been making a demo application to help with learning. I couldn't find much documentation on the templating of views with blade and controllers. Which is the correct method or does it come down to personal

Eloquent filter on pivot table created_at

橙三吉。 提交于 2019-12-31 07:35:08
问题 I want to filter the contents of two tables which have an Eloquent belongsToMany() to each other based on the created_at column in the pivot table that joins them. Based on this SO question I came up with the following: $data = ModelA::with(['ModelB' => function ($q) { $q->wherePivot('test', '=', 1); }])->get(); Here I'm using a simple test column to check if it's working, this should be 'created_at'. What happens though is that I get all the instances of ModelA with the ModelB information if