Skip to content

Instantly share code, notes, and snippets.

@alkavan
Last active June 3, 2023 12:18
Show Gist options
  • Save alkavan/2ab6732dff0b9e499c9ff23e53255d9b to your computer and use it in GitHub Desktop.
Save alkavan/2ab6732dff0b9e499c9ff23e53255d9b to your computer and use it in GitHub Desktop.
Laravel and Artisan Quick Help

Laravel and Artisan Quick Help

Project Creation

composer create-project laravel/laravel hello
cd hello && npm install

Run Development Webserver

php artisan serve

TailwindCSS

Add packages to project:

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init

Create postcss configuration file touch postcss.config.js and put this inside:

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}

Add SASS and tailwind forms plugin:

npm install -D sass sass-loader @tailwindcss/forms

Edit tailwind.config.js to look like this:

/** @type {import('tailwindcss').Config} */
export default {
    content: [
        "./resources/**/*.{php,js}",
    ],
    theme: {
        container: {
            center: true,
        },
        extend: {},
    },
    plugins: [
        require('@tailwindcss/forms'),
    ],
}

Controller

Generate a regular controller

php artisan make:controller AuthController

Generate a resource controller for model (model will be created if not exists)

php artisan make:controller UserController --resource --model=User

Provider

php artisan make:provider AssetManagerProvider

Model

Generate application and database model (-m switch will also generate a migration file).

php artisan make:model Blog -m

Mail

php artisan make:mail WebsiteContact

Migration

Create migration

php artisan make:migration create_flights_table

Run database migrations

php artisan migrate

Rollback migrations

php artisan migrate:rollback

Database Seed

Create seeder class

php artisan make:seeder UserSeeder

Run specific seeder class

php artisan db:seed --class=UserSeeder

Run all seeder classes

php artisan db:seed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment