Displaying a single record from Database in laravel









up vote
2
down vote

favorite
1












I have two methods in my callsController. The first is called newCall and it displays all the records from a DB table, it looks like this :



public function newCall()

$new_calls = new_calls::all(); //fetches everything in the new_calls table in the database
return view('calls.newCall')->with('new_calls', $new_calls); //passes it to the view



This function is working well and all the records are successfully retrieved in my view.



The issue is with the second method viewCall whose aim is to show data for a single call when its name is clicked from the list of newCalls.



Currently, I have just this:



public function viewCall()
return view('calls.viewCall');



I plan on formatting the data from the database (for a particular call) with some static text while displaying it in my viewCall.blade.php.



I wasn't really sure what to put in web.php, so my routes look like this :



Route::get('/calls/newCall', 'CallsController@newCall');
Route::get('/calls/viewCall/id', 'CallsController@viewCall')->name('viewCall');


Can someone help me make this work? I just want to see the associative array with the record from the database when I click on a call's name. What do I need to add in routes and in my view?



This is my newCall.blade.php



<div class="table-responsive">
<table class="table no-margin table-striped">
<thead>
<tr>
<th>Terminal ID</th>
<th>Terminal Name</th>
-- <th>Fault Description</th> --
<th>Call Logged On</th>
<th>ATM Variant</th>
</tr>
</thead>
<tbody>
@if(count($new_calls) > 0)
@foreach($new_calls as $calls)
<tr>
<td><a href="/calls/viewCall/$calls->id" title="view more details">$calls->terminal_id</a></td>
<td>$calls->terminal_name</td>
-- <td style="width:350px">$calls->fault_description</td> --
<td>$calls->created_at</td>
<td>$calls->atm_variant</td>
</tr>
@endforeach
@else
<h1>No new Calls</h1>
@endif
</tbody>
</table>
</div>


This is my viewCall.blade.php



<address>
<strong>$new_call->client_name</strong><br>
$new_call->address<br>
<b>Phone: $new_call->phone</b> <br>
<b>Email: $new_call->email</b>
</address>


nb: I have also tried using $calls->email but it's returning undefined variable: calls and new_calls in each case










share|improve this question























  • Check my answer below and tell me if it works for you or not.
    – rpm192
    Nov 10 at 10:56










  • Add your newcall.blade.php and viewcall.blade.php file and I will look at it.
    – rpm192
    Nov 11 at 11:54










  • Did you updated your viewCall function as shown in my answer below?
    – rpm192
    Nov 11 at 16:48










  • yes...please view the updated version of my post..I included my foreach statement.. am still getting the undefined variable calls error
    – Austin
    Nov 12 at 8:52















up vote
2
down vote

favorite
1












I have two methods in my callsController. The first is called newCall and it displays all the records from a DB table, it looks like this :



public function newCall()

$new_calls = new_calls::all(); //fetches everything in the new_calls table in the database
return view('calls.newCall')->with('new_calls', $new_calls); //passes it to the view



This function is working well and all the records are successfully retrieved in my view.



The issue is with the second method viewCall whose aim is to show data for a single call when its name is clicked from the list of newCalls.



Currently, I have just this:



public function viewCall()
return view('calls.viewCall');



I plan on formatting the data from the database (for a particular call) with some static text while displaying it in my viewCall.blade.php.



I wasn't really sure what to put in web.php, so my routes look like this :



Route::get('/calls/newCall', 'CallsController@newCall');
Route::get('/calls/viewCall/id', 'CallsController@viewCall')->name('viewCall');


Can someone help me make this work? I just want to see the associative array with the record from the database when I click on a call's name. What do I need to add in routes and in my view?



This is my newCall.blade.php



<div class="table-responsive">
<table class="table no-margin table-striped">
<thead>
<tr>
<th>Terminal ID</th>
<th>Terminal Name</th>
-- <th>Fault Description</th> --
<th>Call Logged On</th>
<th>ATM Variant</th>
</tr>
</thead>
<tbody>
@if(count($new_calls) > 0)
@foreach($new_calls as $calls)
<tr>
<td><a href="/calls/viewCall/$calls->id" title="view more details">$calls->terminal_id</a></td>
<td>$calls->terminal_name</td>
-- <td style="width:350px">$calls->fault_description</td> --
<td>$calls->created_at</td>
<td>$calls->atm_variant</td>
</tr>
@endforeach
@else
<h1>No new Calls</h1>
@endif
</tbody>
</table>
</div>


This is my viewCall.blade.php



<address>
<strong>$new_call->client_name</strong><br>
$new_call->address<br>
<b>Phone: $new_call->phone</b> <br>
<b>Email: $new_call->email</b>
</address>


nb: I have also tried using $calls->email but it's returning undefined variable: calls and new_calls in each case










share|improve this question























  • Check my answer below and tell me if it works for you or not.
    – rpm192
    Nov 10 at 10:56










  • Add your newcall.blade.php and viewcall.blade.php file and I will look at it.
    – rpm192
    Nov 11 at 11:54










  • Did you updated your viewCall function as shown in my answer below?
    – rpm192
    Nov 11 at 16:48










  • yes...please view the updated version of my post..I included my foreach statement.. am still getting the undefined variable calls error
    – Austin
    Nov 12 at 8:52













up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I have two methods in my callsController. The first is called newCall and it displays all the records from a DB table, it looks like this :



public function newCall()

$new_calls = new_calls::all(); //fetches everything in the new_calls table in the database
return view('calls.newCall')->with('new_calls', $new_calls); //passes it to the view



This function is working well and all the records are successfully retrieved in my view.



The issue is with the second method viewCall whose aim is to show data for a single call when its name is clicked from the list of newCalls.



Currently, I have just this:



public function viewCall()
return view('calls.viewCall');



I plan on formatting the data from the database (for a particular call) with some static text while displaying it in my viewCall.blade.php.



I wasn't really sure what to put in web.php, so my routes look like this :



Route::get('/calls/newCall', 'CallsController@newCall');
Route::get('/calls/viewCall/id', 'CallsController@viewCall')->name('viewCall');


Can someone help me make this work? I just want to see the associative array with the record from the database when I click on a call's name. What do I need to add in routes and in my view?



This is my newCall.blade.php



<div class="table-responsive">
<table class="table no-margin table-striped">
<thead>
<tr>
<th>Terminal ID</th>
<th>Terminal Name</th>
-- <th>Fault Description</th> --
<th>Call Logged On</th>
<th>ATM Variant</th>
</tr>
</thead>
<tbody>
@if(count($new_calls) > 0)
@foreach($new_calls as $calls)
<tr>
<td><a href="/calls/viewCall/$calls->id" title="view more details">$calls->terminal_id</a></td>
<td>$calls->terminal_name</td>
-- <td style="width:350px">$calls->fault_description</td> --
<td>$calls->created_at</td>
<td>$calls->atm_variant</td>
</tr>
@endforeach
@else
<h1>No new Calls</h1>
@endif
</tbody>
</table>
</div>


This is my viewCall.blade.php



<address>
<strong>$new_call->client_name</strong><br>
$new_call->address<br>
<b>Phone: $new_call->phone</b> <br>
<b>Email: $new_call->email</b>
</address>


nb: I have also tried using $calls->email but it's returning undefined variable: calls and new_calls in each case










share|improve this question















I have two methods in my callsController. The first is called newCall and it displays all the records from a DB table, it looks like this :



public function newCall()

$new_calls = new_calls::all(); //fetches everything in the new_calls table in the database
return view('calls.newCall')->with('new_calls', $new_calls); //passes it to the view



This function is working well and all the records are successfully retrieved in my view.



The issue is with the second method viewCall whose aim is to show data for a single call when its name is clicked from the list of newCalls.



Currently, I have just this:



public function viewCall()
return view('calls.viewCall');



I plan on formatting the data from the database (for a particular call) with some static text while displaying it in my viewCall.blade.php.



I wasn't really sure what to put in web.php, so my routes look like this :



Route::get('/calls/newCall', 'CallsController@newCall');
Route::get('/calls/viewCall/id', 'CallsController@viewCall')->name('viewCall');


Can someone help me make this work? I just want to see the associative array with the record from the database when I click on a call's name. What do I need to add in routes and in my view?



This is my newCall.blade.php



<div class="table-responsive">
<table class="table no-margin table-striped">
<thead>
<tr>
<th>Terminal ID</th>
<th>Terminal Name</th>
-- <th>Fault Description</th> --
<th>Call Logged On</th>
<th>ATM Variant</th>
</tr>
</thead>
<tbody>
@if(count($new_calls) > 0)
@foreach($new_calls as $calls)
<tr>
<td><a href="/calls/viewCall/$calls->id" title="view more details">$calls->terminal_id</a></td>
<td>$calls->terminal_name</td>
-- <td style="width:350px">$calls->fault_description</td> --
<td>$calls->created_at</td>
<td>$calls->atm_variant</td>
</tr>
@endforeach
@else
<h1>No new Calls</h1>
@endif
</tbody>
</table>
</div>


This is my viewCall.blade.php



<address>
<strong>$new_call->client_name</strong><br>
$new_call->address<br>
<b>Phone: $new_call->phone</b> <br>
<b>Email: $new_call->email</b>
</address>


nb: I have also tried using $calls->email but it's returning undefined variable: calls and new_calls in each case







php laravel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 16:14

























asked Nov 9 at 15:00









Austin

2110




2110











  • Check my answer below and tell me if it works for you or not.
    – rpm192
    Nov 10 at 10:56










  • Add your newcall.blade.php and viewcall.blade.php file and I will look at it.
    – rpm192
    Nov 11 at 11:54










  • Did you updated your viewCall function as shown in my answer below?
    – rpm192
    Nov 11 at 16:48










  • yes...please view the updated version of my post..I included my foreach statement.. am still getting the undefined variable calls error
    – Austin
    Nov 12 at 8:52

















  • Check my answer below and tell me if it works for you or not.
    – rpm192
    Nov 10 at 10:56










  • Add your newcall.blade.php and viewcall.blade.php file and I will look at it.
    – rpm192
    Nov 11 at 11:54










  • Did you updated your viewCall function as shown in my answer below?
    – rpm192
    Nov 11 at 16:48










  • yes...please view the updated version of my post..I included my foreach statement.. am still getting the undefined variable calls error
    – Austin
    Nov 12 at 8:52
















Check my answer below and tell me if it works for you or not.
– rpm192
Nov 10 at 10:56




Check my answer below and tell me if it works for you or not.
– rpm192
Nov 10 at 10:56












Add your newcall.blade.php and viewcall.blade.php file and I will look at it.
– rpm192
Nov 11 at 11:54




Add your newcall.blade.php and viewcall.blade.php file and I will look at it.
– rpm192
Nov 11 at 11:54












Did you updated your viewCall function as shown in my answer below?
– rpm192
Nov 11 at 16:48




Did you updated your viewCall function as shown in my answer below?
– rpm192
Nov 11 at 16:48












yes...please view the updated version of my post..I included my foreach statement.. am still getting the undefined variable calls error
– Austin
Nov 12 at 8:52





yes...please view the updated version of my post..I included my foreach statement.. am still getting the undefined variable calls error
– Austin
Nov 12 at 8:52













3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










What you need to do is get the new_calls model by the ID. Which you can do like so:



routes/web.php



Route::get('/calls/viewCall/id', 'CallsController@viewCall');



CallsController.php



public function viewCall($id) // the id in the url

$new_call = new_calls::find($id);

return view('calls.viewCall')->with('new_call', $new_call);



In your view (I assume you're looping through all the calls to display them) create a link.



// your existing foreach
@foreach($x as $y)
<a href="/calls/viewCall/$y->id">View Call</a>
@endforeach





share|improve this answer






















  • That's what return view('calls.viewCall')->with('new_call', $new_call); does. In your view, you can access the call like so: $new_call with any properties.
    – rpm192
    Nov 10 at 16:53











  • Just add the view that you want the link to the call page in and I'll look at it.
    – rpm192
    Nov 10 at 16:55










  • I tried <small class="pull-right">Call logged on: $new_call->created_at </small> and I got the undefined variable new_call error
    – Austin
    Nov 10 at 16:58











  • You should use $new_call->created_at. Because the properties get passed into the view as $new_call
    – rpm192
    Nov 10 at 16:58











  • I also tried that and got the same error
    – Austin
    Nov 10 at 17:01

















up vote
1
down vote













You can do something like this:



public function viewCall($id)

return view('calls.viewCall', ['call' => new_calls::findOrFail($id)]);



This will get the id from the route and call a function to find the object with the given id.



If you have problems to deal with the variable in the view. Try to check the object using dd. Try this:



public function viewCall($id)

$new_call = new_calls::find($id);
dd($new_call);



Ref: https://laravel.com/docs/5.7/controllers#basic-controllers






share|improve this answer






















  • thanks for your response...but I did that but nothing happened..
    – Austin
    Nov 9 at 15:22










  • Do you have any code in viewCall?
    – Laerte
    Nov 9 at 15:25










  • nothing is there except HTML and CSS codes but they are all imported as the headers and the footer
    – Austin
    Nov 9 at 15:48










  • I was hoping to view the data in its raw state ie in array so i can customize the view
    – Austin
    Nov 9 at 15:56






  • 1




    thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
    – Austin
    Nov 12 at 9:02

















up vote
0
down vote













I recommend too looking at naming convetions and route model binding and type hinting in the controller.

Then you'd have something like this:



 public function viewCall(NewCall $newcall)

return view('calls.viewCall')->with($newcall);



and route would be like this:



Route::get('/calls/viewCall/newcall', 'CallsController@viewCall')->name('viewCall');





share|improve this answer




















  • thanks for your response but it says "Class AppHttpControllersNewCall does not exist"
    – Austin
    Nov 9 at 15:45










  • So where you did: $new_call = new_calls::find($id); new_calls is your class. That is poor naming convention. Your model is new_calls and should be singular. Think of a model as 1 row in the DB. new_call::allI() = all rows. new_fall::find($id) == 1 row. I would change my model to NewCall but since you did it like that already you can do: Public function viewCall(new_calls, $newcall) return view('calls.viewCall')->with($newcall); . Now what you are type hinting at is $newcall is an instance of new_call. It is an eloquent.
    – Brad Goldsmith
    Nov 10 at 19:35










  • thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
    – Austin
    Nov 12 at 9:02










  • @Austin . Really read those laravel docs. Route model binding and type hinting are so important and help keep code clean/readable, which will go a long way. Good luck with your project.
    – Brad Goldsmith
    Nov 12 at 14:48










  • thanks for the info...am already on it
    – Austin
    Nov 12 at 16:41










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228169%2fdisplaying-a-single-record-from-database-in-laravel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










What you need to do is get the new_calls model by the ID. Which you can do like so:



routes/web.php



Route::get('/calls/viewCall/id', 'CallsController@viewCall');



CallsController.php



public function viewCall($id) // the id in the url

$new_call = new_calls::find($id);

return view('calls.viewCall')->with('new_call', $new_call);



In your view (I assume you're looping through all the calls to display them) create a link.



// your existing foreach
@foreach($x as $y)
<a href="/calls/viewCall/$y->id">View Call</a>
@endforeach





share|improve this answer






















  • That's what return view('calls.viewCall')->with('new_call', $new_call); does. In your view, you can access the call like so: $new_call with any properties.
    – rpm192
    Nov 10 at 16:53











  • Just add the view that you want the link to the call page in and I'll look at it.
    – rpm192
    Nov 10 at 16:55










  • I tried <small class="pull-right">Call logged on: $new_call->created_at </small> and I got the undefined variable new_call error
    – Austin
    Nov 10 at 16:58











  • You should use $new_call->created_at. Because the properties get passed into the view as $new_call
    – rpm192
    Nov 10 at 16:58











  • I also tried that and got the same error
    – Austin
    Nov 10 at 17:01














up vote
0
down vote



accepted










What you need to do is get the new_calls model by the ID. Which you can do like so:



routes/web.php



Route::get('/calls/viewCall/id', 'CallsController@viewCall');



CallsController.php



public function viewCall($id) // the id in the url

$new_call = new_calls::find($id);

return view('calls.viewCall')->with('new_call', $new_call);



In your view (I assume you're looping through all the calls to display them) create a link.



// your existing foreach
@foreach($x as $y)
<a href="/calls/viewCall/$y->id">View Call</a>
@endforeach





share|improve this answer






















  • That's what return view('calls.viewCall')->with('new_call', $new_call); does. In your view, you can access the call like so: $new_call with any properties.
    – rpm192
    Nov 10 at 16:53











  • Just add the view that you want the link to the call page in and I'll look at it.
    – rpm192
    Nov 10 at 16:55










  • I tried <small class="pull-right">Call logged on: $new_call->created_at </small> and I got the undefined variable new_call error
    – Austin
    Nov 10 at 16:58











  • You should use $new_call->created_at. Because the properties get passed into the view as $new_call
    – rpm192
    Nov 10 at 16:58











  • I also tried that and got the same error
    – Austin
    Nov 10 at 17:01












up vote
0
down vote



accepted







up vote
0
down vote



accepted






What you need to do is get the new_calls model by the ID. Which you can do like so:



routes/web.php



Route::get('/calls/viewCall/id', 'CallsController@viewCall');



CallsController.php



public function viewCall($id) // the id in the url

$new_call = new_calls::find($id);

return view('calls.viewCall')->with('new_call', $new_call);



In your view (I assume you're looping through all the calls to display them) create a link.



// your existing foreach
@foreach($x as $y)
<a href="/calls/viewCall/$y->id">View Call</a>
@endforeach





share|improve this answer














What you need to do is get the new_calls model by the ID. Which you can do like so:



routes/web.php



Route::get('/calls/viewCall/id', 'CallsController@viewCall');



CallsController.php



public function viewCall($id) // the id in the url

$new_call = new_calls::find($id);

return view('calls.viewCall')->with('new_call', $new_call);



In your view (I assume you're looping through all the calls to display them) create a link.



// your existing foreach
@foreach($x as $y)
<a href="/calls/viewCall/$y->id">View Call</a>
@endforeach






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 23:18

























answered Nov 9 at 22:55









rpm192

1,0751417




1,0751417











  • That's what return view('calls.viewCall')->with('new_call', $new_call); does. In your view, you can access the call like so: $new_call with any properties.
    – rpm192
    Nov 10 at 16:53











  • Just add the view that you want the link to the call page in and I'll look at it.
    – rpm192
    Nov 10 at 16:55










  • I tried <small class="pull-right">Call logged on: $new_call->created_at </small> and I got the undefined variable new_call error
    – Austin
    Nov 10 at 16:58











  • You should use $new_call->created_at. Because the properties get passed into the view as $new_call
    – rpm192
    Nov 10 at 16:58











  • I also tried that and got the same error
    – Austin
    Nov 10 at 17:01
















  • That's what return view('calls.viewCall')->with('new_call', $new_call); does. In your view, you can access the call like so: $new_call with any properties.
    – rpm192
    Nov 10 at 16:53











  • Just add the view that you want the link to the call page in and I'll look at it.
    – rpm192
    Nov 10 at 16:55










  • I tried <small class="pull-right">Call logged on: $new_call->created_at </small> and I got the undefined variable new_call error
    – Austin
    Nov 10 at 16:58











  • You should use $new_call->created_at. Because the properties get passed into the view as $new_call
    – rpm192
    Nov 10 at 16:58











  • I also tried that and got the same error
    – Austin
    Nov 10 at 17:01















That's what return view('calls.viewCall')->with('new_call', $new_call); does. In your view, you can access the call like so: $new_call with any properties.
– rpm192
Nov 10 at 16:53





That's what return view('calls.viewCall')->with('new_call', $new_call); does. In your view, you can access the call like so: $new_call with any properties.
– rpm192
Nov 10 at 16:53













Just add the view that you want the link to the call page in and I'll look at it.
– rpm192
Nov 10 at 16:55




Just add the view that you want the link to the call page in and I'll look at it.
– rpm192
Nov 10 at 16:55












I tried <small class="pull-right">Call logged on: $new_call->created_at </small> and I got the undefined variable new_call error
– Austin
Nov 10 at 16:58





I tried <small class="pull-right">Call logged on: $new_call->created_at </small> and I got the undefined variable new_call error
– Austin
Nov 10 at 16:58













You should use $new_call->created_at. Because the properties get passed into the view as $new_call
– rpm192
Nov 10 at 16:58





You should use $new_call->created_at. Because the properties get passed into the view as $new_call
– rpm192
Nov 10 at 16:58













I also tried that and got the same error
– Austin
Nov 10 at 17:01




I also tried that and got the same error
– Austin
Nov 10 at 17:01












up vote
1
down vote













You can do something like this:



public function viewCall($id)

return view('calls.viewCall', ['call' => new_calls::findOrFail($id)]);



This will get the id from the route and call a function to find the object with the given id.



If you have problems to deal with the variable in the view. Try to check the object using dd. Try this:



public function viewCall($id)

$new_call = new_calls::find($id);
dd($new_call);



Ref: https://laravel.com/docs/5.7/controllers#basic-controllers






share|improve this answer






















  • thanks for your response...but I did that but nothing happened..
    – Austin
    Nov 9 at 15:22










  • Do you have any code in viewCall?
    – Laerte
    Nov 9 at 15:25










  • nothing is there except HTML and CSS codes but they are all imported as the headers and the footer
    – Austin
    Nov 9 at 15:48










  • I was hoping to view the data in its raw state ie in array so i can customize the view
    – Austin
    Nov 9 at 15:56






  • 1




    thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
    – Austin
    Nov 12 at 9:02














up vote
1
down vote













You can do something like this:



public function viewCall($id)

return view('calls.viewCall', ['call' => new_calls::findOrFail($id)]);



This will get the id from the route and call a function to find the object with the given id.



If you have problems to deal with the variable in the view. Try to check the object using dd. Try this:



public function viewCall($id)

$new_call = new_calls::find($id);
dd($new_call);



Ref: https://laravel.com/docs/5.7/controllers#basic-controllers






share|improve this answer






















  • thanks for your response...but I did that but nothing happened..
    – Austin
    Nov 9 at 15:22










  • Do you have any code in viewCall?
    – Laerte
    Nov 9 at 15:25










  • nothing is there except HTML and CSS codes but they are all imported as the headers and the footer
    – Austin
    Nov 9 at 15:48










  • I was hoping to view the data in its raw state ie in array so i can customize the view
    – Austin
    Nov 9 at 15:56






  • 1




    thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
    – Austin
    Nov 12 at 9:02












up vote
1
down vote










up vote
1
down vote









You can do something like this:



public function viewCall($id)

return view('calls.viewCall', ['call' => new_calls::findOrFail($id)]);



This will get the id from the route and call a function to find the object with the given id.



If you have problems to deal with the variable in the view. Try to check the object using dd. Try this:



public function viewCall($id)

$new_call = new_calls::find($id);
dd($new_call);



Ref: https://laravel.com/docs/5.7/controllers#basic-controllers






share|improve this answer














You can do something like this:



public function viewCall($id)

return view('calls.viewCall', ['call' => new_calls::findOrFail($id)]);



This will get the id from the route and call a function to find the object with the given id.



If you have problems to deal with the variable in the view. Try to check the object using dd. Try this:



public function viewCall($id)

$new_call = new_calls::find($id);
dd($new_call);



Ref: https://laravel.com/docs/5.7/controllers#basic-controllers







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 16:33

























answered Nov 9 at 15:04









Laerte

5,12132040




5,12132040











  • thanks for your response...but I did that but nothing happened..
    – Austin
    Nov 9 at 15:22










  • Do you have any code in viewCall?
    – Laerte
    Nov 9 at 15:25










  • nothing is there except HTML and CSS codes but they are all imported as the headers and the footer
    – Austin
    Nov 9 at 15:48










  • I was hoping to view the data in its raw state ie in array so i can customize the view
    – Austin
    Nov 9 at 15:56






  • 1




    thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
    – Austin
    Nov 12 at 9:02
















  • thanks for your response...but I did that but nothing happened..
    – Austin
    Nov 9 at 15:22










  • Do you have any code in viewCall?
    – Laerte
    Nov 9 at 15:25










  • nothing is there except HTML and CSS codes but they are all imported as the headers and the footer
    – Austin
    Nov 9 at 15:48










  • I was hoping to view the data in its raw state ie in array so i can customize the view
    – Austin
    Nov 9 at 15:56






  • 1




    thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
    – Austin
    Nov 12 at 9:02















thanks for your response...but I did that but nothing happened..
– Austin
Nov 9 at 15:22




thanks for your response...but I did that but nothing happened..
– Austin
Nov 9 at 15:22












Do you have any code in viewCall?
– Laerte
Nov 9 at 15:25




Do you have any code in viewCall?
– Laerte
Nov 9 at 15:25












nothing is there except HTML and CSS codes but they are all imported as the headers and the footer
– Austin
Nov 9 at 15:48




nothing is there except HTML and CSS codes but they are all imported as the headers and the footer
– Austin
Nov 9 at 15:48












I was hoping to view the data in its raw state ie in array so i can customize the view
– Austin
Nov 9 at 15:56




I was hoping to view the data in its raw state ie in array so i can customize the view
– Austin
Nov 9 at 15:56




1




1




thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
– Austin
Nov 12 at 9:02




thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
– Austin
Nov 12 at 9:02










up vote
0
down vote













I recommend too looking at naming convetions and route model binding and type hinting in the controller.

Then you'd have something like this:



 public function viewCall(NewCall $newcall)

return view('calls.viewCall')->with($newcall);



and route would be like this:



Route::get('/calls/viewCall/newcall', 'CallsController@viewCall')->name('viewCall');





share|improve this answer




















  • thanks for your response but it says "Class AppHttpControllersNewCall does not exist"
    – Austin
    Nov 9 at 15:45










  • So where you did: $new_call = new_calls::find($id); new_calls is your class. That is poor naming convention. Your model is new_calls and should be singular. Think of a model as 1 row in the DB. new_call::allI() = all rows. new_fall::find($id) == 1 row. I would change my model to NewCall but since you did it like that already you can do: Public function viewCall(new_calls, $newcall) return view('calls.viewCall')->with($newcall); . Now what you are type hinting at is $newcall is an instance of new_call. It is an eloquent.
    – Brad Goldsmith
    Nov 10 at 19:35










  • thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
    – Austin
    Nov 12 at 9:02










  • @Austin . Really read those laravel docs. Route model binding and type hinting are so important and help keep code clean/readable, which will go a long way. Good luck with your project.
    – Brad Goldsmith
    Nov 12 at 14:48










  • thanks for the info...am already on it
    – Austin
    Nov 12 at 16:41














up vote
0
down vote













I recommend too looking at naming convetions and route model binding and type hinting in the controller.

Then you'd have something like this:



 public function viewCall(NewCall $newcall)

return view('calls.viewCall')->with($newcall);



and route would be like this:



Route::get('/calls/viewCall/newcall', 'CallsController@viewCall')->name('viewCall');





share|improve this answer




















  • thanks for your response but it says "Class AppHttpControllersNewCall does not exist"
    – Austin
    Nov 9 at 15:45










  • So where you did: $new_call = new_calls::find($id); new_calls is your class. That is poor naming convention. Your model is new_calls and should be singular. Think of a model as 1 row in the DB. new_call::allI() = all rows. new_fall::find($id) == 1 row. I would change my model to NewCall but since you did it like that already you can do: Public function viewCall(new_calls, $newcall) return view('calls.viewCall')->with($newcall); . Now what you are type hinting at is $newcall is an instance of new_call. It is an eloquent.
    – Brad Goldsmith
    Nov 10 at 19:35










  • thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
    – Austin
    Nov 12 at 9:02










  • @Austin . Really read those laravel docs. Route model binding and type hinting are so important and help keep code clean/readable, which will go a long way. Good luck with your project.
    – Brad Goldsmith
    Nov 12 at 14:48










  • thanks for the info...am already on it
    – Austin
    Nov 12 at 16:41












up vote
0
down vote










up vote
0
down vote









I recommend too looking at naming convetions and route model binding and type hinting in the controller.

Then you'd have something like this:



 public function viewCall(NewCall $newcall)

return view('calls.viewCall')->with($newcall);



and route would be like this:



Route::get('/calls/viewCall/newcall', 'CallsController@viewCall')->name('viewCall');





share|improve this answer












I recommend too looking at naming convetions and route model binding and type hinting in the controller.

Then you'd have something like this:



 public function viewCall(NewCall $newcall)

return view('calls.viewCall')->with($newcall);



and route would be like this:



Route::get('/calls/viewCall/newcall', 'CallsController@viewCall')->name('viewCall');






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 15:22









Brad Goldsmith

1019




1019











  • thanks for your response but it says "Class AppHttpControllersNewCall does not exist"
    – Austin
    Nov 9 at 15:45










  • So where you did: $new_call = new_calls::find($id); new_calls is your class. That is poor naming convention. Your model is new_calls and should be singular. Think of a model as 1 row in the DB. new_call::allI() = all rows. new_fall::find($id) == 1 row. I would change my model to NewCall but since you did it like that already you can do: Public function viewCall(new_calls, $newcall) return view('calls.viewCall')->with($newcall); . Now what you are type hinting at is $newcall is an instance of new_call. It is an eloquent.
    – Brad Goldsmith
    Nov 10 at 19:35










  • thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
    – Austin
    Nov 12 at 9:02










  • @Austin . Really read those laravel docs. Route model binding and type hinting are so important and help keep code clean/readable, which will go a long way. Good luck with your project.
    – Brad Goldsmith
    Nov 12 at 14:48










  • thanks for the info...am already on it
    – Austin
    Nov 12 at 16:41
















  • thanks for your response but it says "Class AppHttpControllersNewCall does not exist"
    – Austin
    Nov 9 at 15:45










  • So where you did: $new_call = new_calls::find($id); new_calls is your class. That is poor naming convention. Your model is new_calls and should be singular. Think of a model as 1 row in the DB. new_call::allI() = all rows. new_fall::find($id) == 1 row. I would change my model to NewCall but since you did it like that already you can do: Public function viewCall(new_calls, $newcall) return view('calls.viewCall')->with($newcall); . Now what you are type hinting at is $newcall is an instance of new_call. It is an eloquent.
    – Brad Goldsmith
    Nov 10 at 19:35










  • thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
    – Austin
    Nov 12 at 9:02










  • @Austin . Really read those laravel docs. Route model binding and type hinting are so important and help keep code clean/readable, which will go a long way. Good luck with your project.
    – Brad Goldsmith
    Nov 12 at 14:48










  • thanks for the info...am already on it
    – Austin
    Nov 12 at 16:41















thanks for your response but it says "Class AppHttpControllersNewCall does not exist"
– Austin
Nov 9 at 15:45




thanks for your response but it says "Class AppHttpControllersNewCall does not exist"
– Austin
Nov 9 at 15:45












So where you did: $new_call = new_calls::find($id); new_calls is your class. That is poor naming convention. Your model is new_calls and should be singular. Think of a model as 1 row in the DB. new_call::allI() = all rows. new_fall::find($id) == 1 row. I would change my model to NewCall but since you did it like that already you can do: Public function viewCall(new_calls, $newcall) return view('calls.viewCall')->with($newcall); . Now what you are type hinting at is $newcall is an instance of new_call. It is an eloquent.
– Brad Goldsmith
Nov 10 at 19:35




So where you did: $new_call = new_calls::find($id); new_calls is your class. That is poor naming convention. Your model is new_calls and should be singular. Think of a model as 1 row in the DB. new_call::allI() = all rows. new_fall::find($id) == 1 row. I would change my model to NewCall but since you did it like that already you can do: Public function viewCall(new_calls, $newcall) return view('calls.viewCall')->with($newcall); . Now what you are type hinting at is $newcall is an instance of new_call. It is an eloquent.
– Brad Goldsmith
Nov 10 at 19:35












thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
– Austin
Nov 12 at 9:02




thanks...I made some errors in my variable names and I have corrected them..my code now workes....thanks soo much... i really appreciate
– Austin
Nov 12 at 9:02












@Austin . Really read those laravel docs. Route model binding and type hinting are so important and help keep code clean/readable, which will go a long way. Good luck with your project.
– Brad Goldsmith
Nov 12 at 14:48




@Austin . Really read those laravel docs. Route model binding and type hinting are so important and help keep code clean/readable, which will go a long way. Good luck with your project.
– Brad Goldsmith
Nov 12 at 14:48












thanks for the info...am already on it
– Austin
Nov 12 at 16:41




thanks for the info...am already on it
– Austin
Nov 12 at 16:41

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228169%2fdisplaying-a-single-record-from-database-in-laravel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto