Ad

Laravel: Send An Array Through Route

- 1 answer

I was trying to send an array through a route to another view, but when i used the function get_defined_vars(), i realized that i was sending a string with the information. Is it possible to do that?

this form from my view should send the array to my route

            <form action="/trans" method="POST">
                @csrf
                <div class="input-group">
                  <input type="hidden" class="form-control" name="r" value="{{$cooperado}}">
                    <button type="submit" class="btn btn-primary">
                      <span>+</span>
                    </button>
                  </span>
                </div>
            </form>

then this route should send the array to the other view

Route::post('/trans',  function(){
    $j = Input::get('r');
    return view('movs.create')->with(['j'=>$j]);
});

this is the controller

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Movimentacoes;
class MovimentacoesController extends Controller
{
public function create()
    {
        //
        return view('movs.create');
    }
}
Ad

Answer

routes.php

Route::post('/trans',  '[email protected]');

controller

use Illuminate\Http\Request;
use App\Movimentacoes;

class MovimentacoesController extends Controller
{
    public function create(Request $request)
    {
        $j = $request->request->get('r');
        return view('movs.create')->with(['j' => $j]);
    }
}
Ad
source: stackoverflow.com
Ad