One to One Relationship

Suppose You have a users table and passports table. Each user has only one passport number. On this case, you can one to one relationships

cd Directory
php artisan tinker
DB::table('users')->insert(['name'=>Amir,'created_at'=>new DateTime,'updated_at'=>new DateTime])
DB::table('passports')->insert(['number'=>'998787545782','user_id'=>'1','created_at'=>new DateTime,'updated_at'=>new DateTime]);

Now you have to create model for user and passport

cd Directory
php artisan make:model user
php artisan make:model passport

user model:


namespace App;

use Illuminate\Database\Eloquent\Model;

class user extends Model
    public function passport(){
    	//return $this->hasOne('App\passport');
    	return $this->hasOne(Passport::class);

passport model:


namespace App;

use Illuminate\Database\Eloquent\Model;

class mobile extends Model
    public function user(){
    	return $this->belongsTo(User::class);

Retrieve the related record:


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\user;

class HomeController extends Controller
    public function index(){
    	$passport_data = user::find(1)->passport;    	
    	return view('welcome',compact('passport_data'));

Laravel Snippets

Incorrect Paths to assets - css and js
The issue is on localhost. I did not created custom virtual host.
However using {{asset('path')}} location seems to work everywhere.

Laravel 5.3 - Clear config cache in shared hosting
config:clear command just deletes bootstrap/cache/config.php file, 
so just delete this file manually.

Laravel Documentation

Installing Laravel

Laravel utilizes Composer to manage its dependencies. So, before using Laravel, make sure you have Composer installed on your machine.

php composer.phar create-project --prefer-dist laravel/laravel portfolio "5.5.*"

Start Local Development Server:

cd DirectoryName
php artisan serve

This command will start a development server at http://localhost:8000:


artisan is a command line interface that means artisan have a lots of command.

Artisan list

cd DirectoryName
php artisan


blade is a laravel default template engine. You can use special syntax.

Create Controller and Routes

Command in your terminal:

cd DirectoryName
php artisan make:controller ControllerName

index, create, store, show, update, edit, delete

cd DirectoryName
php artisan make:controller SongsController --resource

Routing list

routes > web.php


cd DirectoryName
php artisan route:list

Create db table

cd DirectoryName
php artisan make:migration create_galleries_table --create=galleries
php artisan migrate


cd DirectoryName
php artisan tinker
DB::table('songs')->insert(['title'=>'Bangladesh','artist'=>'James','created_at'=>new DateTime,'updated_at'=>new DateTime]);
come out from the tinker just press ctrl+c


The most important thing is your model name must be singular

cd DirectoryName
php artisan make:model song

If you want to create model and migration together

cd DirectoryName
php artisan make:model todo -m


The database will have to change in 2 directory
root directory > .env
config > database.php
after that restart your server

helper and plugins installation

1.go then version select
2.You can see installation code composer.json file and add following code
4.then you have to update the composer go to
after composer installation then update composer.phar file.
command in your terminal:
#php composer.phar update
6.Next you have to add provider and aliases just follow the laravelcollective