当我们新增成功之后,
就会回到列表页,
这时候我们要补做两个动作,
一个是把之前没有处理完的列表处理好,
另外一个是当成功的时候,
要显示成功的讯息,
这部分之前使用者的时候有做过,
直接贴过来就可以.
首先要在 app/Http/Controllers/AdminController.php 加入result的判断
//心情随笔列表页面public function mindListPage(){ Log::notice('取得心情随笔列表'); //先取得自己的资料 $User = $this->GetUserData(); //取得心情随笔列表 $mindPaginate = Mind::where('user_id', $User->id)-> paginate(5); $name = 'mind'; //接收输入资料 $input = request()->all(); $result = ''; if(isset($input['result'])) $result = $input['result']; $binding = [ 'title' => ShareData::TITLE, 'page' => $this->page, 'name' => $name, 'User' => $User, 'mindPaginate' => $mindPaginate, 'result' => $result, ]; return view('admin.mindlist', $binding);}
在这里我们有做分页的动作,
paginate(5)表示每页5笔资料,
如果超过就会显示页码,
换页的动作Laravel会自己处理,
我们可以不用在意.
接着要修改 resources/views/admin/mindlist.blade.php 如下:
<!-- 指定继承 layout.master 母模板 -->@extends('layout.master')<!-- 传送资料到母模板,并指定变数为title -->@section('title', $title)<!-- 传送资料到母模板,并指定变数为content -->@section('content')<div class="normal_form"> <div class="form_title">心情随笔列表</div> <div class="btn_group"> <button type="button" class="btn btn-primary btn_form" onclick="AddData()">新增</button> </div> <div class="table-responsive"> <table class="table table-hover form_label"> <thead> <tr> <th>日期</th> <th>内容</th> <th></th> </tr> </thead> <tbody> @foreach($mindPaginate as $data) <tr> <td>{{ $data->created_at }}</td> <td>{{ $data->content }}</td> <td class="right"> <button type="button" class="btn btn-success btn_form" onclick="EditData({{ $data->id }})">修改</button> </td> </tr> @endforeach </tbody> </table> {{-- 分页页数按钮 --}} {{ $mindPaginate->links() }} </div><div><link href="/css/iao-alert.css" rel="stylesheet" type="text/css" /><script src="/js/iao-alert.jquery.js"></script><script> $( document ).ready(function() { <?PHP if($result == "success") { echo('Success("修改资料成功!")'); } ?> }); //显示吐司讯息 function Success(message) { $.iaoAlert({ type: "success", mode: "dark", msg: message, }) } //新增心情随笔 function AddData() { location.href = "/admin/mind/add"; } //编辑心情随笔 function EditData($id) { location.href = "/admin/mind/" + $id + "/edit"; }</script>@endsection
当进入心情随笔页就会看到
而当新增完资料跳回画面就会看到右上角的成功讯息