1

I have a issue with passing data. I create a get request in controller
function path to send data and blade template to receive some content but that is not working :D

i try changing web.php few times but, last error i got is non static method

web.php

Route::get('/test2', function () {
return view('test2')->with('testGet@show');;
});

testGet

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class testGet extends Controller
{
  public function show(Request $request)
  {
    $data = $request -> input();
  } 
}

and test2.blade.php

<body>
@php
    use App\Http\Controllers\testGet ;
    echo testGet::show();
@endphp
<div class="emptySpace"> {{$data}}</div>

I expecting to load blade view with data get from url, i already create view but now i need to pass some data... any idea?

3 Answers 3

4

Route

Route::get('/test2', 'testGet@show');

Now, you can send variable using compact in controller like this:

Controller

public function show(Request $request)
{
    $data = $request -> input();
    return view('test2', compact('data'));
} 

OR

 public function show(Request $request)
{
    $array['data'] = $request -> input();
    $array['data2'] = "test";
    $array['data3'] = [32,43,54];
    return view('test2', $array);

    //By this you can send multiple data 
}

Now, you can use data in view like this:

View

<div class="emptySpace"> {{$data}}</div>
Sign up to request clarification or add additional context in comments.

3 Comments

same issue. non static method
after fixing test.blade error gone... but new one come true xD after type name=piotr i gto error like: Trying to get property 'name' of non-object" in my blade template offcorse i did something like that $data->name
@Piter $data is an array not collection, You have to access like $data['name']
0
namespace App\Http\Controllers;
use Illuminate\Http\Request;

class testGet extends Controller
{
  public function show(Request $request)
  {
    $data = ['name'=>'apple','category'=>'fruits'];
    return view('test2',compact('data'));

   } 
}

 // in your view 

{{$data}}

Comments

0

Route

Route::get('/test2', 'testGet@show'); 

Goto Controller : testGet ->show

public function show(Request $request)
{   
     $data = $request -> input();
     return view('test2', compact('data'));
} 

Don't import any thing in View.....Just add your html code

<div class="emptySpace"> {{$data}}</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.