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
}