How can I manually return or throw a validation error/exception in Laravel?

前端 未结 5 682
我在风中等你
我在风中等你 2020-12-12 19:36

Have a method that\'s importing CSV-data into a Database. I do some basic validation using

class CsvImportController extends Controller
{
    public functio         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 20:18

    you can try a custom message bag

    try
    {
        // Call the rabbit hole of an import method
    }
    catch(\Exception $e)
    {
        return redirect()->to('dashboard')->withErrors(new \Illuminate\Support\MessageBag(['catch_exception'=>$e->getMessage()]));
    }
    

提交回复
热议问题