PHP (Laravel)
Server Setup
Install Laravel
Environmental Variables
Developing for Laravel
Develop Web Pages
Route::get('test', 'TestController@index'); // Laravel also supports adding a function instead of handling class // This one returns a view module without any logic. Route::get('/', function () { return view('welcome'); });# Generate controller file using this command php artisan make:controller TestController vi app/Http/Controllers/TestController.phpclass TestController extends Controller { //Router TestController@index goes here public function index() { // Simply return a view module return view('test'); } }# Create test view file vi resources/views/test.blade.php<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Hello</title> </head> <body> Testing. </body> </html>Route::post('note', 'NoteController@store');# Generate controller file using this command php artisan make:controller NoteController vi app/Http/Controllers/NoteController.phppublic function store(Request $request) { // We are using model Note. // This create API is provided by Laravel. $note = Note::create([ 'title' => $request->title, 'author' => $request->author, 'content' => $request->content, ]); // Assume the request is ajax, we respond with a JSON. return response()->json([ 'status' => 0, 'msg' => '', 'data' => $note ], 201); // If it is a form submit, we can also redirect user to a page. // Below we direct the user back to where he/she came from. // return back()->withInput(); }# -m tells Laravel to create model for us at the same time php artisan make:migration Note -m vi database/migrations/DATETIME_create_notes_table.phppublic function up() { Schema::create('notes', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('title', 100)->default(''); $table->string('author', 100)->default(''); $table->string('content', 800)->default(''); $table->timestamps(); }); } public function down() { Schema::dropIfExists('notes'); }# Run your scripts (all of them) to create the table php artisan migrate # Now edit our model file vi app/Note.php// Add the column names that were used in Note::create at our controller // Otherwise Laravel won't let us insert like that protected $fillable = ['title', 'author', 'content'];// routes/web.php // In case your url path is long, we can give it a name like this. // So we can easily get this url string anywhere in our app. Route::get('note', 'NoteController@showNotes')->name('note');// app/Http/Controllers/NoteController.php# Install the front end package prepared by Laravel # This command sometimes takes up to a few minuts composer require laravel/ui --dev # Generate basic scaffolding. Choose one. php artisan ui bootstrap php artisan ui vue php artisan ui react # Install the scaffolding npm install# If you haven't already composer require laravel/ui --dev # Generate login / registration scaffolding. Choose one. php artisan ui bootstrap --auth php artisan ui vue --auth php artisan ui react --auth # Install the scaffolding npm install # Generate final assets npm run dev
Develop APIs
Log
Query your database
Last updated