MyBlog
  • Login
  • Register
  1. Main

From the Firehose

Laravel 9 Vue JS Live Search

2 years ago by admin

Step 1: Install Laravel 9 App

    composer create-project --prefer-dist laravel/laravel blogf

Step 2: Connecting App to Database .env

    DB_CONNECTION=mysql 
    DB_HOST=127.0.0.1 
    DB_PORT=3306 
    DB_DATABASE=here database name here
    DB_USERNAME=here database username here
    DB_PASSWORD=here database password here

Step 3: Run Make auth Command

    cd blog
    composer require laravel/ui --dev
    php artisan ui vue --auth

Step 4: Create Model and Migration and Controller

    php artisan make:model Post -fm

          Open create_posts_table.php migration:

     public function up()
    {
       Schema::create('posts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title');
            $table->string('slug');
            $table->unsignedBigInteger('user_id');
            $table->timestamps();
      });
    }
     php artisan migrate 

           Navigate to app/Models/Post.php:

    <?php
 
        namespace App\Models;
        
        use Illuminate\Database\Eloquent\Factories\HasFactory;
        use Illuminate\Database\Eloquent\Model;
        
        class Post extends Model
        {
            use HasFactory;
            protected $guarded = [];
        }    

         Factory   

        Navigate to database/factories and open PostFactory.php:        

    public function definition()
    {
        $title = fake()->sentence();
        $slug = Str::slug($title);
        return [
            'title' => $title,
            'slug' => $slug,
            'user_id' => 1
        ];
    }    
    php artisan tinker
    //and then
    App\Models\User::factory()->count(10)->create();
    App\Models\Post::factory()->count(30)->create();
    exit

    

Category: Laravel | Comments: 2
  • Newer
  • Older

Showing 61 to 61 of 61 results

  • ‹
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • ›

About

Customize this section to tell your visitors a little bit about your publication, writers, content, or something else entirely. Totally up to you.

Categories

  1. Laravel
  2. Linux
  3. Git
  4. JavaScript
  5. NextJS
  6. Node.js
  7. SQL
  8. Windows
Place sticky footer content here.