1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#install composer sudo apt-get install curl sudo curl -s https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer #go to absolute dir composer create-project laravel/laravel:^9.0 app-name composer require livewire/livewire composer require laravel/ui php artisan livewire:publish #install nvm curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash source ~/.bashrc #20 = version 20 nvm install 20 npm install tailwindcss @tailwindcss/forms @tailwindcss/typography npx tailwindcss init npm install laravel-mix --save-dev npm run dev #migrate db php artisan migrate #make livewire component php artisan make:livewire componentName |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#make seeder php artisan make:seeder TableSeeder #TableSeeder.php namespace Database\Seeders; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; use DB; class TableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { DB::table('tableName')->insert([ 'name' => "Hello", ]); } } #DatabaseSeeder.php #add the code public function run() { $this->call([ ... TableSeeder::class, ]); } #run seeder php artisan db:seed / php artisan db:seed --class=TableSeeder #clean all data & run seeder again php artisan migrate:fresh --seed / php artisan migrate:fresh --seed --seeder=TableSeeder |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#make Test php artisan make:test YourTaskTest #go to tests/Feature/YourTaskTest.php #add the code below use App\Models\TheTableModelName; use App\Http\Livewire\TheComponentName; #if test livewire component use Livewire\Livewire; #if test livewire component class YourTaskTest extends TestCase{ public function test_1() { $user = User::where("name","ABC")->first(); $response = $this->actingAs($user); #pretend 'ABC' user Livewire::test(AddComment::class) #test livewire component ->set('var1', 1) #livewire public variable if have to set ->set('var2', 'test') ->call('componentFunctionName') #test livewire component function name ->assertStatus(200); #result status 200 then pass } public function test_2() { $user = User::where("name","ABC")->first(); $response = $this->actingAs($user)->get('/'); #pretend 'ABC' user goto "/" url $response->assertStatus(200); #result status 200 then pass #or $response->assertSee("TextYourSupposeToGet"); #result contain the text then pass } public function test3() { $response = $this->post('/postURL', [ 'title' => 'Test Post', 'content' => 'This is a test post', ]); $response->assertStatus(201); // Check if the response status is 201 (Created) $response->assertJson([ 'message' => 'Post created successfully!', 'data' => [ 'title' => 'Test Post', 'content' => 'This is a test post', ], ]); } } #run test php artisan test |