Skip to content

Instantly share code, notes, and snippets.

@luckyshot
Last active February 23, 2021 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luckyshot/4ee16a49039b1ddd1d24c3eccbdc1789 to your computer and use it in GitHub Desktop.
Save luckyshot/4ee16a49039b1ddd1d24c3eccbdc1789 to your computer and use it in GitHub Desktop.
Laravel Speed Coding Notes and Command Reference

Create the MySQL database in: utf8mb4 unicode 520 ci

Virtual Host setup

sudo code /usr/local/etc/httpd/extra/httpd-vhosts.conf (WSL: sudo nano /etc/apache2/sites-available/000-default.conf)

sudo code /etc/hosts

sudo apachectl -k restart (WSL: sudo service apache2 restart)

Create the Laravel project

cd /WWW/

laravel new example.com

composer global require laravel/installer

composer create-project --prefer-dist laravel/laravel example.com

cd example.com

if laravel command not found

sudo nano ~/.bash_profile

export PATH=~/.config/composer/vendor/bin:$PATH

source ~/.bash_profile

Laravel Authentication

composer require laravel/breeze --dev php artisan breeze:install

Config files

code config/app.php

code .env

Run migrations

php artisan migrate

<?php
// Documentation: https://laravel.com/docs/5.8/migrations#creating-columns
function up(){
Schema::create('messages', function($table){
$table->increments('id');
$table->string('title');
$table->timestamps(); // created_at, updated_at
});
}
function down(){
Schema::drop('messages');
}
# Create a new site (it will create a new folder in the current directory i.e. `./example.com`)
laravel new example.com
# Give writing permissions to these directories
storage
bootstrap/cache
# Configure global parameters, environment parameters come later
code config/app.php
# Other interesting ones:
code config/cache.php
code config/database.php
code config/mail.php
code config/session.php
# Don't forget to commit changes!
php artisan config:cache
# Set application key
php artisan key:generate
# Open `.env` and customize
code .env
# Enable authentication (creates Controllers, Models and Views)
php artisan make:auth
#### Now we are ready to code ####
# Show a list of artisan jobs
php artisan
# Show how to auto-generate the barebones of a controller
php artisan help make:controller
php artisan make:controller indexController
# Creating migrations (see migration.php file in this gist for more)
php artisan make:migration create_messages_table
# Once done:
php artisan migrate
# To rollback
php artisan migrate:rollback --step=1
# To reset
php artisan migrate:reset
code routes/web.php
<?php
// Documentation: https://laravel.com/docs/5.8/routing
Route::get('/', 'indexController@index');
Route::get('/message/{id}', 'messageController@view');
Route::get('/contact', 'indexController@about');
Route::get('/about', 'indexController@contact');
Route::get('/terms-of-use', 'indexController@termsOfUse');
Route::get('/privacy-policy', 'indexController@privacyPolicy');
Route::get('/cookie-policy', 'indexController@cookiePolicy');
<?php
// View form:
<form ...>
{{ csrf_field }}
</form>
// Saving the form
use Illuminate/Http/Request;
public function create(Request $request){
$message = new Message();
$message->title = $request->title;
$message->save();
return redirect('/');
}
// Viewing the Message
public function view($id){
$message->findOrFail($id); // will 404 if not found
return view('message', ['message' => $message]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment