Laravel Form methods VS traditional coding

Using built-in HTML helpers have many benefits: Using Form::open you add CSRF protection input hidden (by default) Using form elements (inputs/textarea etc.) and withInput method for Redirection allows you to easily fill in the form with the same data with almost no coding If you use Redirect::route(‘form’->withInput(); and have input text {{Form::text(‘username’)}} it will automatically … Read more

Can one modify the templates created by artisan migrate command?

It’s doable in a fairly logical way, at least in Laravel 5 Subclass MigrationCreator and override getStubPath(), just copying the function over from the original class (it will use your subclass’s __DIR__) <?php namespace App\Database; use Illuminate\Database\Migrations\MigrationCreator; class AppMigrationCreator extends MigrationCreator { public function getStubPath() { return __DIR__.’/stubs’; } } Write a service provider to … Read more

Laravel Many to many self referencing table only works one way

Instead of creating two records use a new function. public function friends() { return $this->belongsToMany(‘User’, ‘friend_user’, ‘user_id’, ‘friend_id’); } // Same table, self referencing, but change the key order public function theFriends() { return $this->belongsToMany(‘User’, ‘friend_user’, ‘friend_id’, ‘user_id’); } //You can then call opposite record(s) using: foreach( Auth::user()->theFriends as $theFriends ) I used this approach … Read more

Laravel: Change base URL?

First change your application URL in the file config/app.php (or the APP_URL value of your .env file): ‘url’ => ‘http://www.example.com’, Then, make the URL generator use it. Add thoses lines of code to the file app/Providers/AppServiceProvider.php in the boot method: \URL::forceRootUrl(\Config::get(‘app.url’)); // And this if you wanna handle https URL scheme // It’s not usefull … Read more

PHP7 Constructor class name

As I understand this, in PHP4 my code was buggy, but not in PHP7, right? Not quite. PHP4-style constructors still work on PHP7, they are just been deprecated and they will trigger a Deprecated warning. What you can do is define a __construct method, even an empty one, so that the php4-constructor method won’t be … Read more

Laravel MySql DB Connection with SSH

Here’s a workable solution of working with a database hosted on an EC2 instance via SSH w/ a key. First, setup a corresponding connection in your database config: ‘mysql_EC2’ => array( ‘driver’ => ‘mysql’, ‘host’ => ‘127.0.0.1:13306’, ‘database’ => ‘EC2_website’, ‘username’ => ‘root’, ‘password’ => ‘xxxxxxxxxxxxxxxx’, ‘charset’ => ‘utf8’, ‘collation’ => ‘utf8_unicode_ci’, ‘prefix’ => ”, … Read more