Reference Youtube link https://www.youtube.com/watch?v=CHSL0Btbj_o
at 1:49:45
Reference Github repo: https://github.com/John-Weeks-Dev/tiktok-clone
composer require laravel/breeze --dev
php artisan breeze:install
Which Breeze stack would you like to install?
Blade with Alpine ...................................................................................... blade
Livewire (Volt Class API) with Alpine ............................................................... livewire
Livewire (Volt Functional API) with Alpine ............................................... livewire-functional
React with Inertia ..................................................................................... react
Vue with Inertia ......................................................................................... vue
API only ................................................................................................. api
// select API only
Create a user by using laravel tinker. Run command php artisan tinker
in the terminal. Once the tinker terminal starts running, run the below command to create a user.
App\Models\User::create(["name"=>"Pranav Peter","email"=>"[email protected]","password"=>bcrypt("123123123")]);
Type in exit
to exit the laravel tinker Psy Shell (tinker terminal)
Apparently, Laravel Sanctum gets installed while installing Laravel Breeze. Read Sanctum related documentation here.
Edit the session related .env variable as below
SESSION_DRIVER=cookie
# This is for the backend
SESSION_DOMAIN=localhost
# This is for the frontend
SANCTUM_STATEFUL_DOMAINS=localhost:3000
php artisan make:controller Api/UserController --resource
php artisan make:resource UserCollection
There are some changes in the users
table, so we run php artisan migrate:reset
to clear the data and edit the users-table-migration file.
Schema::create('users', function (Blueprint $table) {
...
$table->string('bio')->nullable();
$table->text('image')->nullable();
...
});
Then we need to make relevant changes in RegisteredUserController
and Users
model file.
We need to install the below package. Read more about the package here
composer require intervention/image-laravel
Next, add the configuration files to your application using the vendor:publish
command:
php artisan vendor:publish --provider="Intervention\Image\Laravel\ServiceProvider"
This command will publish the configuration file image.php
to your app/config
directory. In this file you can set the desired driver for Intervention Image. By default the library is configured to use GD library for image processing.
The integration is now complete and it is possible to access the ImageManager
via Laravel's facade.
use Intervention\Image\Laravel\Facades\Image;
Route::get('/', function () {
$image = Image::read('images/example.jpg');
});
We create a Service
called FileService
to handle the user profile image upload.
php artisan make:controller Api/GlobalController --resource
php artisan make:model Post -mc --resource
// create AllPostsCollection
php artisan make:resource AllPostsCollection
php artisan make:controller Api/ProfileController --resource
php artisan make:controller Api/HomeController --resource
php artisan make:model Comment -mc --resource
php artisan make:model Like -mc --resource
// create AllPostsCollection
php artisan make:resource AllPostsCollection
Define the API endpoints in api.php
. This completes all steps for the backend.