$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar create-project laravel/laravel my-project.com --prefer-dist
Para instalar vendor es necesario la libreria mbstring
$ sudo apt-get install php7.0-mbstring php7.0-xml
Verificar si hay errores antes de lanzar el server
$ php artisan clear-compile
Iniciando el servidor:
$ php artisan serve
Listar puertos disponibles:
$ netstat -lntu
$ netstat -lntu --man
Iniciar serve especificando puerto
$ php artisan serve --port=8080
Crear un middleware
$ php artisan make:middleware VerifyCsrfToken
Que version de Laravel tengo:
$ php artisan --version
Create model
$ php artisan make:model Project
$ php artisan make:model Task
Creo las tablas en la bd
$ php artisan migrate:refresh
$ php artisan migrate:refresh --seed && php artisan db:seed --class=PermissionSeeder
Creo las tablas y cargo con data
$ php artisan migrate:refresh --seed
Crear modelo
php artisan make:model Account
php artisan make:migration customers
php artisan make:migration create_business_unit_user_table --create=Account
php artisan make:migration create_attachments_table --create=Attachment
creo un seeder por modelo
$ php artisan make:seeder UsersTableSeeder
- delete all tables in your database
- $ php artisan migrate:refresh
- Refresh composer: $ composer dump-autoload
https://stackoverflow.com/questions/31263637/how-to-convert-laravel-migrations-to-raw-sql-scripts Este comando no altera las tablas ya existentes
$ php artisan migrate --pretend --no-ansi > migrate.sql
- Artisan’s handy features – tinker. (more details: http://blog.enge.me/)
- Tinker provides a command line for interacting with your Laravel installation. As an example, let’s use it to retrieve the number of projects currently in the database:
$ php artisan tinker
>App\Project::count();
3
>App\Task::count();
7
>App\Models\User::first();
>App\Models\User::first()->business_units;
Save many to many
$business = BusinessUnit::first();
$user->business_units()->save($business);
$user = App\Models\User::first();
$business->users()->save($user)
Create Migration
$ php artisan make:migration create_user_has_user_table
Added some data seeds Create /database/seeds/ProjectsTableSeeder.php and TasksTableSeeder.php like so:
<?php
// /database/migrations/seeds/ProjectsTableSeeder.php
use Illuminate\Database\Seeder;
class ProjectsTableSeeder extends Seeder {
public function run()
{
// Uncomment the below to wipe the table clean before populating
DB::table('projects')->delete();
$projects = array(
['id' => 1, 'name' => 'Project 1', 'slug' => 'project-1', 'created_at' => new DateTime, 'updated_at' => new DateTime],
['id' => 2, 'name' => 'Project 2', 'slug' => 'project-2', 'created_at' => new DateTime, 'updated_at' => new DateTime],
['id' => 3, 'name' => 'Project 3', 'slug' => 'project-3', 'created_at' => new DateTime, 'updated_at' => new DateTime],
);
// Uncomment the below to run the seeder
DB::table('projects')->insert($projects);
}
}
?>
Also don’t forget to add your seed classes to /database/seeds/DatabaseSeeder.php:
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder {
public function run()
{
Model::unguard();
$this->call('ProjectsTableSeeder');
$this->call('TasksTableSeeder');
}
}
Now we seed:
$ php ../composer.phar dump-autoload
Or generating autoload files
$ php artisan migrate:refresh --seed
if we updated a row, these commands change it. Create Controllers
$ php artisan make:controller ProjectsController
$ php artisan make:controller TasksController
Create controller with all its methods
$ php artisan make:controller --resource PagesController
Configured our URL structure Nested Resources Begin by adding the Project and Task resources to /app/Http/routes.php:
Route::get('/', function () {
return view('welcome');
});
Route::resource('projects','ProjectsController');
Route::resource('projects.tasks','TasksController');
Route::resource('tasks','TasksController');
//Route::get('/', 'WelcomeController@index');
//Route::get('home', 'HomeController@index');
//Route::controllers([
// 'auth' => 'Auth\AuthController',
// 'password' => 'Auth\PasswordController',
//]);
Let’s now look at a neat little artisan feature
$ php artisan route:list
So we’d get for example /projects/my-first-project/tasks/buy-milk.
In /app/Http/routes.php and drop the following in:
Route::bind('tasks', function($value, $route) {
return App\Task::whereSlug($value)->first();
});
Route::bind('projects', function($value, $route) {
return App\Project::whereSlug($value)->first();
});
The above will override the default behavior for the tasks and projects wildcards in php artisan routes.
/*
- Artisan */
$ php artisan vendor:publish --tag=public --force
Laravel 5
We can still use another migration:
$ php artisan make:migration update_users
$ php artisan make:migration create_mytable
$ php artisan make:migration create_my_table --create="my_table"
Sample
$ php artisan make:migration create_table_roles
- run migration
$ php artisan migrate
- run seeder database if no exists table this command create its:
$ php artisan migrate:refresh --seed
$ php artisan db:seed --class=DatabaseSeeder
$ php artisan db:seed --class=PermissionSeeder
$ php artisan config:clear
Laravel 5.5.43 Error No application encryption key has been specified. New Laravel app Solution : php artisan key:generate
$ php artisan route:list
- Create controller in subfolder
$ php artisan make:controller "Admin\BrandsController" --resource
Clear caches
php artisan config:cache
# con esto solucionamos un error de leer el .env
php artisan config:clear
php artisan cache:clear
php artisan view:cache
php artisan view:clear
php artisan optimize --force
php artisan config:cache
php artisan route:cache