美文网首页
laravel 5.4框架的日常使用笔记

laravel 5.4框架的日常使用笔记

作者: 塞外务农 | 来源:发表于2018-04-24 13:54 被阅读0次

因为学习过了5.1之后,基本的东西就不再做介绍了

自定义错误返回机制一

php artisan make:request bannerCheckUpload;
<?php

namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;

class bannerCheckUpload extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'alt' => 'bail|required|max:45'
        ];
    }

    public function messages()
    {
        return [
            'alt.required' => '图片的提示不能为空'
        ];
    }
}
<?php

namespace App\Http\Controllers;

use App\Http\Requests\bannerCheckUpload;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Validation\Validator;

class BannerController extends Controller
{
    public function uploading(bannerCheckUpload $request)
    {
        
    }
}

自定义错误返回机制二

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BannerController extends Controller
{
    public function uploading(Request $request)
    {
        $message = [
            'alt.required'=>'账号不能为空!',
            'link.required'=>'密码不能为空!',
        ];
        $this->validate($request, [
            'alt' => 'required|max:10',
            'link' => 'required',
        ],$message);
    }
}

相关文章

网友评论

      本文标题:laravel 5.4框架的日常使用笔记

      本文链接:https://www.haomeiwen.com/subject/tvcjlftx.html