1

I am trying to pass data from one page to another via hyperlink. Here is url.

<a href="{{url('page-name/sometext')}}">click here </a>

My Route:-

Route::get('page-name/{sometext}', 'MyController@pagename');

In Controller:-

function pagename(Request $request){
        $sometext=$request->sometext;
        return view('page-name')-with($sometext);
}

Now trying to get data in second page.

{{$sometext}}

But it showing that error:-

Object of class Illuminate\View\View could not be converted to int

Kindly suggest, if there is another way for this!

Sajjad Ali
  • 156
  • 9

2 Answers2

1

You're using get method and get with parameter. so there is no need to write Request $request

HTML

<a href="{{url('page-name/sometext')}}">click here </a>

Route:-

Route::get('page-name/{sometext}', 'MyController@pagename');

Controller:- needs to change

function pagename($sometext){
        return view('page-name',compact('sometext'));
}

Now page-name.blade.php file you can get this variable as

{{ $sometext }}
Dilip Hirapara
  • 14,810
  • 3
  • 27
  • 49
  • it works but now the page url has changed from http://127.0.0.1:8000/page-name to http://127.0.0.1:8000/page-name/sometext, so this page not connecting with other [css/js/bootstrap] files cz these were connected with the page http://127.0.0.1:8000/page-name .how to overcome this one? – Sajjad Ali Oct 21 '19 at 09:03
  • I think that issue is of loading css js. You can `ctrl+U` and check the url. – Dilip Hirapara Oct 21 '19 at 09:05
  • i set css, js url according to 127.0.0.1:8000/page-name bcz there will be multiple text variables will be sent to the page, and the page url will contineously change like 127.0.0.1:8000/page-name/text-one, 127.0.0.1:8000/page-name/text-two etc, then how to set css, js, bootstrap links for that page. – Sajjad Ali Oct 21 '19 at 09:10
  • 2
    @SajjadAli have you tried linking your css, js, or anything within your public folder using `{{ asset('css/style.css') }}`. This way you won't have to manually change your linking as it will always point to your public folder. UNLESS you linked it directly from a website (e.g bootstrap's cdn, jquery library online, etc) – Steven Oct 21 '19 at 09:11
  • 1
    tried, but was not sure why to use asset, thank you – Sajjad Ali Oct 21 '19 at 09:42
0

When you pass data in route with get method like this,

Route::get('page-name/{sometext}', 'MyController@pagename');

then you need to define number of parameter in your method as,

function pagename(Request $request,$someText=""){
        //$sometext=$request->sometext;
        return view('page-name')-with("someText",$someText);
}