dougan6402 2017-04-24 21:33
浏览 245

如何在if-else语句LARAVEL中返回一个视图

I am new to php and I am wondering how it would be possible to return a view within if-else statement in laravel. I prefer not to use laravel specific stuff, but if I need to, ofc. I will.

Here is a simple example of code, where I check whether the Form input(Name of an author) can go trough validation.If not -I want to show the view with the Form again along with errors, else - DB::insert.. The problem is I can't use return in this case. It will be much appreciated if you can tell me the right way to validate data: THANK YOU in advance!

<?php
 class HomeController extends Controller
    {
    public function authorInput()
        {
        $typeAuthor = Input::get('typeAuthor');
        $author= new Model1();
        $std=$author->checkAuthors($typeAuthor); 
        $bam = array_map(function ($value)          // dolnoto e alternativa
            {
            return (array) $value;
            }, $std);  

        $arr = array();
        if (count($bam) > 0)
            {
            $arr[] = 'This name has already been included';

            }
        if (mb_strlen($typeAuthor) < 2)
            {
            $arr[] = 'The Name should include more than 1 symbol';

            }
        return view('viewAddAuthor', compact('arr'));    
        else
            {
            ....DB::insert
            }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作