Skip to content

Instantly share code, notes, and snippets.

View EmmanuelObua's full-sized avatar
🏠
Working from home

Emmanuel Obua EmmanuelObua

🏠
Working from home
View GitHub Profile
@EmmanuelObua
EmmanuelObua / composer.txt
Last active May 12, 2021 13:48
Composer installation
composer create-project --prefer-dist laravel/laravel:^7.0 laravel-eloquent
@EmmanuelObua
EmmanuelObua / AppServiceProvider.php
Last active May 13, 2021 07:05
App Service Provider
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
//Add the schema facade
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
@EmmanuelObua
EmmanuelObua / artisan.php
Created May 13, 2021 07:23
Models and Migration Artisan command
//These commands generates models and their respective migration files
php artisan make:model Post -m
php artisan make:model Profile -m
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProfilesTable extends Migration
{
/**
* Run the migrations.
@EmmanuelObua
EmmanuelObua / posts-schema.php
Last active May 13, 2021 08:38
Posts migration
<?php
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
//It can be done like this as well in a more simplified way
//$table->foreignId('user_id')->constrained();
@EmmanuelObua
EmmanuelObua / user-profile-relationship.php
Created May 13, 2021 09:49
User model with profile relationship
<?php
/**
* User
*
* @author Obua Emmanuel <eobua6882@gmail.com>
* @copyright 2021 Obua Emmanuel
* @link http://emmanuelobua.me
* @version 1.0.0
*
<?php
/**
* ProfileController
*
* @author Obua Emmanuel <eobua6882@gmail.com>
* @copyright 2021 Obua Emmanuel
* @link http://www.emmanuelobua.me
* @version 1.0.0
*
@EmmanuelObua
EmmanuelObua / profile.blade.php
Last active May 13, 2021 14:05
Profile blade
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Dashboard') }}</div>
@EmmanuelObua
EmmanuelObua / user-post-relationship.php
Created May 14, 2021 09:30
User post relationship
<?php
/**
* User
*
* @author Obua Emmanuel <eobua6882@gmail.com>
* @copyright 2021 Obua Emmanuel
* @link http://emmanuelobua.me
* @version 1.0.0
*