composer create-project --prefer-dist laravel/laravel .
composer create-project --prefer-dist laravel/laravel="8.0.*" .
f:\laravel9_api_server>git init
f:\laravel9_api_server>git add .
f:\laravel9_api_server>git commit –m "Install Laravel Template"
f:\laravel9_api_server>git remote add origin https://github.com/SergeyHub/laravel9_dingo_api.git
f:\laravel9_api_server>git push -u origin master
Let's start SQL Shell (psql). The program will prompt you to enter the name
of the server, database, port and user. You can click/skip these items as they
will use the default values
(for server - localhost, for database - postgres, for port - 5432,
as user - postres superuser).
Next, you will need to enter a password for the user
(by default, the postgres user): 123456 (in my case)
postgres=# create database db_name;
database list
select datname from pg_database;
pg_dump dbname > outfile
Edit env. file
DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=cargo
DB_USERNAME=postgres
DB_PASSWORD=123456
mysql -u root -p
create database crud_api; db_name;
drop database db_name;
show databases;
use db_name;
show tables;
drop table table_name;
exit
Edit env. file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=crud_api
DB_USERNAME=root
DB_PASSWORD=123456
composer require api-ecosystem-for-laravel/dingo-api
composer remove api-ecosystem-for-laravel/dingo-api
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
Edit env. file
API_STANDARDS_TREE=vnd
API_SUBTYPE=storeapi
API_VERSION=v1
API_PREFIX=api
API_NAME=StoresAPI
API_DEBUG=true
git init
git add .
git commit –m "Comment"
git remote add origin https://github.com/SergeyHub/laravel_crud_api_vue_back.git
git push -u origin master
composer require tymon/jwt-auth:*
Edit config/app.php file
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
#####3.1 Publish the config
Run the following command to publish the package config file:
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
You should now have a config/jwt.php file that allows you to configure the basics of this package.
#####3.2 Generate secret key
php artisan jwt:secret
This will update your .env file with something like JWT_SECRET=foobar
Edit config/api.php file
'auth' => [
'jwt' => 'Dingo\Api\Auth\Provider\JWT'
],
php artisan make:model Post --all --api
php artisan make:model Comment --all --api
php artisan make:model Post_User
php artisan migrate
git add .
git commit –m "Comment"
git push -u origin master
seeders->Traits
php artisan db:seed
php artisan tinker
Psy Shell v0.11.8 (PHP 8.1.8 — cli) by Justin Hileman
>>> \App\Models\Post::find(1)
=> App\Models\Post {#4101
id: 1,
title: "untitled",
body: "[]",
created_at: "2022-10-26 19:04:39",
updated_at: "2022-10-26 19:04:39",
}
>>> \App\Models\Post::find(10)
=> App\Models\Post {#4717
id: 10,
title: "untitled",
body: "[]",
created_at: "2022-10-26 19:04:39",
updated_at: "2022-10-26 19:04:39",
}
>>> \App\Models\Post::find(10)->comments
=> Illuminate\Database\Eloquent\Collection {#4714
all: [
App\Models\Comment {#3765
id: 2,
body: "[]",
user_id: 2,
post_id: 10,
created_at: "2022-10-26 19:04:39",
updated_at: "2022-10-26 19:04:39",
},
],
}
>>>
php artisan make:controller UserController
git push -u origin master
php artisan make:model Sclass --all
php artisan make:controller Api/Sclass --resource
php artisan make:model Subject -m
php artisan make:controller Api/SubjectController --resource
git push -u origin master
php artisan make:model Section -m
php artisan make:controller Api/SectionController --resource
php artisan make:model Student -m
php artisan migrate
php artisan make:controller Api/StudentController --resource
http://localhost:8000/api/products/5
method PUT
x-www-form-urlencoded
body
key value
name Iphone 5 updated
description product description updated
git add .
git commit -m "16. Product Model Migrateion Controller Request"
git push -u origin master
####17. Post resource. DB Transaction post_user table
php artisan make:resource PostResource
![Screenshot](readme/db transaction.JPG)
http://localhost:8000/api/v1/posts?page=1&page_size=7
git push -u origin master
php artisan make:exception GeneralJsonException
Event Listener = function listens to an event
php artisan make:event Models/Post/PostCreated
php artisan make:event Models/Post/PostUpdated
php artisan make:event Models/Post/PostDeleted
Edit \app\Events\Models\Post\PostCreated.php
namespace App\Events\Models\Post;
use App\Models\Post;
protected $post;
public function __construct( $post )
{
$this->post = $post;
}
Edit \app\Repositories\PostRepository.php
use App\Models\Post;
use App\Events\Models\Post\PostCreated;
use App\Events\Models\Post\PostDeleted;
use App\Events\Models\Post\PostUpdated;
event(new PostCreated($created));
event(new PostUpdated($post));
event(new PostDeleted($post));
php artisan make:listener SendWelcomeEmail
Edit \app\Listeners\SendWelcomeEmail.php
public function handle($event)
{
dump("Email sent.");
}
php artisan make:subscriber PostSubscriber
Edit \app\Providers\EventServiceProvider.php
php artisan make:mail WelcomeMail
Edit app\Mail\WelcomeMail.php
Create \resources\views\mail
php artisan notifications:table
php artisan migrate
php artisan make:notification SendEmaiNotification
php artisan make:controller HomeController
Testing configuration file : phpunit.xml
php artisan make:test --help
php artisan make:test --unit PostRepositoryTest
vendor\bin>phpunit --filter=PostRepositoryTest
php artisan test
#####Get Posts List