Answer the question
In order to leave comments, you need to log in
How to properly organize data output in laravel view?
Hi all.
There are 2 buttons and routes for them.
1) /add-code
2) /add-item
After clicking on the first button, I return to the /root page
After clicking on the second button, I also return to the /root
page On the /root page there are 2 standard bootstrap tabs, in the first view it is displayed variable {{ $msg }}
return view('root')->with(['msg' => '10 кодов добавлено в базу']);
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Codes;
use App\Item;
class RootHomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth:root');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function addCode(Request $request)
{
if($request->isMethod('post')) {
$arrayName = array();
$i = 0;
while ($i < 1) {
$chars="qazxswedcvfrtgbnhyujmkiolp1234567890QAZXSWEDCVFRTGBNHYUJMKIOLP";
$max=10;
$size=StrLen($chars)-1;
$password=null;
while($max--)
$password.=$chars[rand(0,$size)];
$arrayName[$i] = $password;
//Добавляем данные в бд
Codes::insert(['code' => $arrayName[$i]]);
$i++;
}
return view('root')->with(['msg' => '10 кодов добавлено в базу']);
}
}
public function addItem(Request $request)
{
if ($request->isMethod('POST')){
Item::create([
'name' => $request->name,
'description' => $request->desc,
]);
return view('root'); // здесь ошибка
//нужно потому что вот типа того - > return view('root')->with(['msg' => '10 кодов добавлено в базу']);
}
}
public function index()
{
// $add = addCode();
return view('root')->with(['msg' => 'После нажатия кнопки, будет добавлено 10 кодов']);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question