zoukankan      html  css  js  c++  java
  • laravel 实现增 与查

    //调用模型层

    <?php
    namespace App;
    use IlluminateSupportFacadesDB;
    use IlluminateDatabaseEloquentModel;
    class teach extends Model
    {
    //数据表
        public $table='teach';
    //定义主键
       public $primarkey='id';
    //时间戳
        public $timestamps=true;
    //白名单
        protected $fillable=['updated_at','created_at','name','sex','tel','id'];
    }

     

    <?php
    namespace AppHttpControllers;
    use AppSchool;
    use App each;
    use IlluminateHttpRequest;
    use IlluminateSupportFacadesDB;
    class TeachController extends Controller
    {

         //首页
       public function index()
         {
             return view('teachers.teach');

         }

    }

    teach.blade.php:

    @extends('layouts.app')

    @section('content')
    <a href="{{ route('teach.create') }}" style="padding:5px;border:1px dashed gray;">
    + New Teacher
    </a>
    @endsection

    //实现添加

    public function create()
    {
        return view('teachers.into');
    }

    into.blade.php:

    @extends('layouts.app')

    @section('content')
    <form action="{{ route('teach.store') }}" method="post">
    {{ csrf_field() }}
    {{--//防跨域攻击--}}
    <label>姓名:</label>
    <input type="text" name="name" style="100%;" value="{{ old('name') }}">
    <label>性别:</label>
    <input name="sex" rows="10" style="100%;">{{ old('sex') }}
    <label>电话:</label>
    <input name="tel" rows="10" style="100%;">{{ old('tel') }}
    <button type="submit">OK</button>
    </form>

    @endsection


    //接收数据 入库
    public function store(Request $request){
         $teach=new Teach();
         $teach->name =$request->name;
         $teach->sex = $request->sex;
         $teach->tel = $request->tel;
         if( $teach->save()){
                return $this->into();
         }

    }

    //分页展示数据

    public function into(){
         $users = DB::table('teach')->paginate(3);
          return view('teachers.index', ['users' => $users]);
    }

    index.blade.php:

    @extends('layouts.app')

    @section('content')
    <a href="{{ route('teach.create') }}" style="padding:5px;border:1px dashed gray;">
    + New Teacher
    </a>

    @foreach ($users as $teacher)
        <div style="border:1px solid gray;margin-top:20px;padding:20px;">
         <h2>{{ $teacher->name }}</h2>
         <p>{{ $teacher->sex }}</p>
        <p>{{ $teacher->tel }}</p>
         <p>{{ $teacher->created_at }}</p>
         <p>{{ $teacher->updated_at }}</p>
          <a href="{{ route('teach.edit', $teacher->id ) }}">Edit</a>
    <form action="{{ route('teach.destroy', $teacher->id) }}" method="post" style="display: inline-block;">
    {{ csrf_field() }}
    {{ method_field('DELETE') }}
         <button type="submit" style="color: #F08080;background-color: transparent;border: none;">Delete</button>
    </form>

    </div>
       @endforeach
    @endsection

  • 相关阅读:
    删除XML文档中某节点
    水晶报表之创建子报表
    给字符串中的每个字符加上单引号
    Failed to export using the options you specified. Please check your options and try again
    从ASP.NET传递参数给水晶报表
    两个文本框异动任何一个能即时更新计算结果
    添加节点至XML文档中去
    读取XML文档存入泛型List<T>集合中
    泛型List<T>转存为XML文档
    怎样创建XML文档
  • 原文地址:https://www.cnblogs.com/chaihtml/p/10532646.html
Copyright © 2011-2022 走看看