Laravel 5.4 创建待办事项

准备事项

本环境使用 Laragon 集成 php-7.1.1、nginx-1.10.1、mariadb-10.2.3、composer、nodejs。

需要创建一个todo 的数据库,创建一个 todo 的表

最终效果

1. 创建 laravel 5.4 项目

通过 Laravel 安装工具创建 laravel 5.4 项目

1.1 通过 composer 安装 Laravel 工具

composer global require "laravel/installer"

1.2 安装 laravel 5.4 项目

laravel new laratodo

2. 创建数据库相关

2.1 创建数据库

create database todo default charset utf8

2.2 数据库迁移文件

2.2.1 修改user表的迁移文件

public function up()

{

Schema::create('users', function (Blueprint $table) {

$table->increments('id');

$table->string('name');

$table->string('email')->unique();

$table->string('password');

$table->string('userimage'); //此行为新增

$table->string('api_key')->nullable()->unique(); //此行为新增

$table->rememberToken();

$table->timestamps();

});

}

2.2.1 修改todo表的迁移文件

php artisan make:migration create_todo_table //创建todo的数据库迁移文件

public function up()

{

Schema::create('todo', function (Blueprint $table) {

$table->increments('id');

$table->string('todo');

$table->string('description');

$table->string('category');

$table->integer('user_id')->unsigned();

$table->timestamps();

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

});

}

2.3 配置数据库链接 .env 文件

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=todo

DB_USERNAME=root

DB_PASSWORD=

2.4 执行数据库迁移

php artisan migrate

3. 创建模型相关

3.1 User 模型

namespace App;

use Illuminate\Notifications\Notifiable;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable

{

use Notifiable;

/**

* The attributes that are mass assignable.

*

* @var array

*/

protected $fillable = [

'name', 'email', 'password','userimage'

];

/**

* The attributes that should be hidden for arrays.

*

* @var array

*/

protected $hidden = [

'password', 'remember_token',

];

/*

* Get Todo of User

*

*/

public function todo()

{

return $this->hasMany('App\Todo');

}

}

3.2 Todo 模型

3.2.1 创建 Todo 模型

//此方法可以创建控制器和模型

php artisan make:controller TodoController --resource --model=Todo

3.2.1 编辑 Todo 模型

namespace App;

use Illuminate\Database\Eloquent\Model;

class Todo extends Model

{

protected $table = 'todo';

protected $fillable = ['todo','category','user_id','description'];

}

4. 创建控制器

4.1 编辑 TodoController

namespace App\Http\Controllers;

use App\Todo;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Validator;

use Illuminate\Support\Facades\Auth;

class TodoController extends Controller

{

public function __construct()

{

$this->middleware('auth');

}

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$result = Auth::user()->todo()->get();

if(!$result->isEmpty()){

return view('todo.dashboard',['todos'=>$result,'image'=>Auth::user()->userimage]);

}else{

return view('todo.dashboard',['todos'=>false,'image'=>Auth::user()->userimage]);

}

}

/**

* Show the form for creating a new resource.

*

* @return \Illuminate\Http\Response

*/

public function create()

{

return view('todo.addtodo');

}

/**

* Store a newly created resource in storage.

*

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

*/

public function store(Request $request)

{

$this->validator($request->all())->validate();

if(Auth::user()->todo()->Create($request->all())){

return $this->index();

}

}

/**

* Display the specified resource.

*

* @param \App\Todo $todo

* @return \Illuminate\Http\Response

*/

public function show(Todo $todo)

{

return view('todo.todo',['todo' => $todo]);

}

/**

* Show the form for editing the specified resource.

*

* @param \App\Todo $todo

* @return \Illuminate\Http\Response

*/

public function edit(Todo $todo)

{

return view('todo.edittodo',['todo' => $todo]);

}

/**

* Update the specified resource in storage.

*

* @param \Illuminate\Http\Request $request

* @param \App\Todo $todo

* @return \Illuminate\Http\Response

*/

public function update(Request $request, Todo $todo)

{

$this->validator($request->all())->validate();

if($todo->fill($request->all())->save()){

return $this->show($todo);

}

}

/**

* Remove the specified resource from storage.

*

* @param \App\Todo $todo

* @return \Illuminate\Http\Response

*/

public function destroy(Todo $todo)

{

if($todo->delete()){

return back();

}

}

protected function validator(array $request)

{

return Validator::make($request, [

'todo' => 'required',

'description' => 'required',

'category' => 'required'

]);

}

}

4.2 编辑 LoginController 和 RegisterController 控制器

protected $redirectTo = '/home'; => protected $redirectTo = '/todo';

5. 创建视图

在 views 创建 todo 文件夹

5.1 创建 dashboard.blade.php

@extends('layouts.app')

@section('title', 'Home ')

@section('content')

@if($todos != false)

[@foreach](https://learnku.com/users/5651) ($todos as $todo)

{{$todo->todo}}

@endforeach

@else

No Todo added yet click here to add new todo.

@endif

@endsection

5.2 创建 edittodo.blade.php

@extends('layouts.app')

@section('title', 'Edit')

@section('content')

{{ csrf_field() }}

{{ method_field('PUT') }}

Todo

@if ($errors->has('todo'))

{{ $errors->first('todo') }}

@endif

Category

@if ($errors->has('category'))

{{ $errors->first('category') }}

@endif

Description

{{$todo->description}}

@if ($errors->has('description'))

{{ $errors->first('description') }}

@endif

Update

@endsection

5.3 创建 addtodo.blade.php

@extends('layouts.app')

@section('title', 'Add New Todo')

@section('content')

{{ csrf_field() }}

Todo

@if ($errors->has('todo'))

{{ $errors->first('todo') }}

@endif

Category

@if ($errors->has('category'))

{{ $errors->first('category') }}

@endif

Description

@if ($errors->has('description'))

{{ $errors->first('description') }}

@endif

Add

@endsection

5.4 创建 todo.blade.php

@extends('layouts.app')

@section('title', title_case($todo->todo))

@section('content')

{{title_case($todo->todo)}} window.Laravel = {!! json_encode([

'csrfToken' => csrf_token(),

]) !!};

Toggle Navigation

Home

@if (Auth::guest())

LoginRegister

@else

{{ Auth::user()->name }}

  • οnclick="event.preventDefault();

    document.getElementById('logout-form').submit();">

    Logout

    {{ csrf_field() }}

  • Add Todo

@endif

@yield('content')

5.6 编辑 register.blade.php

//在form 加上

//在注册表单上加上

Image

@if ($errors->has('userimage'))

{{ $errors->first('userimage') }}

@endif

5. 创建路由

Route::get('/', function () {

return redirect('/login');

});

Auth::routes();

Route::resource('todo','TodoController');

6. 添加 Storage

php artisan storage:link

修改config/filesystems.php

//修改图片访问路径

'default' => 'local', => 'default' => 'public',

参考

https://www.cloudways.com/blog/create-todo-app-laravel-5-4/

https://www.cloudways.com/blog/laravel-5-4-todo-app-setting-authentication-functionality/

//github

https://github.com/ahmedkhan847/todoapplaravel

大功告成

本作品采用《CC 协议》,转载必须注明作者和本文链接

持续做一件事,必定有所成就

php待办事项设计,Laravel 5.4 创建待办事项相关推荐

  1. java待办功能 设计_高效人士的待办清单都用这些软件来做

    为了保证工作和生活上时间的高效,我们很多人都会借助待办软件来列下每天或者中短期内需要做的事情,确保不会忘记并能起到一定的督促作用,让自己更加自律. 应用市场上的 todo(待办)软件很多,一搜一大堆, ...

  2. 系统待办事项设计_B端产品工作台设计详解

    编辑导语:B端产品的设计更多地是为了提高企业员工的工作效率,而工作台的设计则是为了提高员工使用B端产品的效率,因此,工作台对B端产品而言具有非常重要的意义:本文作者详细介绍了B端产品工作台设计内容. ...

  3. 企业微信如何创建待办事项?

    日常工作中总会有一些重要事项需要按时完成,否则会影响工作进度,为了避免遗忘可以在企业微信上创建待办事项. 前言 在日常工作中,每天都有各种各样的工作内容需要完成,而且有些重要事项需要按时去完成,否则会 ...

  4. 如何建立工作待办事项?工作便签中的待办事项清单建立方法

    每一份工作都不容易,对于大多数人来说,每天的工作堆成了山,这里面有大事也有小事,有紧急的事情也有不紧急的事情.如果不分主次一起干,很难有良好的效果.如果能列出待办事项清单,可以很容易知道现在该做什么事 ...

  5. oa导入表格html,点晴OA工作流表单模板创建注意事项(Word、Excel复制粘贴变形如何解决)...

     点晴OA工作流表单模板创建注意事项(Word.Excel复制粘贴变形如何解决) 很多用户反映点晴OA系统中工作流表单创建时对于表格的控制十分的麻烦,希望能够做出漂亮的效果,但往往事违人愿.下面将工作 ...

  6. 我翻译的一篇文章,OO设计中对象的创建和使用

    OO设计中对象的创建和使用 转载于:https://www.cnblogs.com/lishu1980/archive/2006/06/22/432526.html

  7. dingo php,用laravel dingo/api创建简单的api

    这篇文章主要介绍了关于用laravel dingo/api创建简单的api,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 1,修改.env配置文件添加API_STANDARDS_TRE ...

  8. ad19 导出step 没有pcb_PCB设计导出Gerber基本操作及注意事项(三)

    继续科普PCB设计导出Gerber基本操作及注意事项,来到系列文章的第三篇,列举一下导出制板文件通用的注意事项,无论是用AD.PADS.Allegro.eagle还是其他的PCB设计软件,都能适用的规 ...

  9. 某电商网站的数据库设计(6)——创建查询销售数据的视图

    某电商网站的数据库设计(6)--创建查询销售数据的视图 目录 某电商网站的数据库设计(6)--创建查询销售数据的视图 1.统计总的销售信息 2.按日期分组统计 3.按店铺分组统计--全店汇总 4.按销 ...

最新文章

  1. C语言 编写程序:由键盘输入一个字符判断是字母数字还是其他符号。
  2. c#垂直投影法_投影学
  3. Scala与Java差异(三)之函数
  4. oracle客户端中文乱码问题的解决
  5. [MS bug]安装SQL Server 2008 错误:is not a valid login or you do not have permission
  6. sql 纵向求和_sql 行列转换 求和平均值等
  7. 学习HTMLT5_1 拖拽
  8. 《项目经验》静态页面图片找不到
  9. 计算机房设计规范2008,GB50174-2008 电子计算机机房设计规范
  10. cass小插件集合_CASS插件合集 - 下载 - 搜珍网
  11. 85 缓存, 验证码 序列化
  12. 恒凯USB数据采集卡在国产麒麟操作系统下的应用(一)环境设置、采集卡驱动安装及C语言采集应用
  13. 【冷冻电镜入门】加州理工公开课课程笔记 Part 3: Image Formation
  14. 计算机自动维护有用吗,Win10系统关闭自动维护功能提高系统运行速度
  15. 从键盘上输入以下的数据:TOM:89|JERRY:90|TONY:95,数据格式为“姓名:成绩|姓名:成绩|姓名:成绩”,对输入的内容按成绩进行排序,并将结果按成绩由高到低排序。
  16. 办公软件的安装,简单操作进行安装office操作步骤。
  17. 【Data truncation: Data too long for column ‘XXX at row 1 报错】
  18. VTK 学习----3D基础知识-着色器和图形管道
  19. Android webview 清除历史访问记录
  20. 今天的区块链现状是九十年代的互联网?

热门文章

  1. 从链家到贝壳 — 数字化转型的完美标杆
  2. 短信猫通过超级终端进行配置和调试
  3. Ubunto的一些快捷键
  4. pt100专用芯片_贴片式pt100温度传感器,生产厂家,尺寸定制,德国进口技术芯片...
  5. 计算机系统与网络安全-简答题复习
  6. 2022创新中国企业家论坛暨天心集团六周年年会成功举行
  7. 基于YOLO模型的安全帽佩戴检测
  8. linux open函数功能,open(
  9. DirectShow环境配置及常见错误解决方案
  10. LoRaWAN介绍5 对手