Coder Social home page Coder Social logo

tiktok-clone-api's Introduction

Laravel Logo

Build Status Total Downloads Latest Stable Version License

Tiktok clone backend using Laravel

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

Install Laravel Breeze

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

Laravel Tinker

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)

Set up Laravel Sanctum

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

IMPORTANT: Make sure to change the port for laravel app, eg. http://localhost:8040

Make UserController and UserCollection

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.

Handing user Image upload

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.

Create GlobalController

php artisan make:controller Api/GlobalController --resource

Define Post model, migration and controller

php artisan make:model Post -mc --resource

// create AllPostsCollection
php artisan make:resource AllPostsCollection

Create ProfileController

php artisan make:controller Api/ProfileController --resource

Create HomeController

php artisan make:controller Api/HomeController --resource

Define Comment model, migration and controller

php artisan make:model Comment -mc --resource

Define Like model, migration and controller

php artisan make:model Like -mc --resource

// create AllPostsCollection
php artisan make:resource AllPostsCollection

Create API endpoints

Define the API endpoints in api.php. This completes all steps for the backend.

tiktok-clone-api's People

Contributors

pranavpeter2050 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.