企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
安装: git clone https://github.com/laravel/quickstart-basic quickstart cd quickstart composer install php artisan migrate 数据库迁移: php artisan make:migration create_tasks_table --create=tasks 该命令生成的迁移文件位于项目根目录下的database/migrations目录,可能你已经注意到了,make:migration命令已经在迁移文件中为我们添加了自增ID和时间戳,接下来我们要编辑该文件添加更多的列到数据表tasks: Eloquent模型: php artisan make:model Task **设置可写:chmod 777 -R storage/** .env配置: APP_ENV=local APP_DEBUG=true APP_KEY=b809vCwvtawRbsG0BmP1tWgnlXQypSKf APP_URL=http://localhost DB_HOST=127.0.0.1 DB_DATABASE=task DB_USERNAME=root DB_PASSWORD=000000 CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 MAIL_DRIVER=smtp MAIL_HOST=mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null blade模板: layout: @yield('content') 子模板: @extends('layouts.app') @section('content') @include('common.errors') {{ csrf_field() }} {{ method_field('DELETE') }}伪造delete @foreach ($tasks as $task) @endforeach @if (count($tasks) > 0) @endif @endsection 路由: use App\Task; use Illuminate\Http\Request; Route::group(['middleware' => ['web']], function () { /** * Show Task Dashboard */ Route::get('/', function () { return view('tasks', [ 'tasks' => Task::orderBy('created_at', 'asc')->get() ]); }); /** * Add New Task */ Route::post('/task', function (Request $request) { $validator = Validator::make($request->all(), [ 'name' => 'required|max:255', ]); if ($validator->fails()) { return redirect('/') ->withInput() ->withErrors($validator); } $task = new Task; $task->name = $request->name; $task->save(); return redirect('/'); }); /** * Delete Task */ Route::delete('/task/{id}', function ($id) { Task::findOrFail($id)->delete(); return redirect('/'); }); });