Laravel define function in controller
Created at 22-Aug-2022 ,
By samar
Laravel define function in controller
In this tutorial, we will try to find the solution to "Laravel define function in controller" through programming.
You can define a function in controller class of Laravel. You have to use public, private or protected function keyword with function name like `public function index(){` to define a function in Laravel.-
public function show($id) { return view('user.profile', [ 'user' => User::findOrFail($id) ]); }
Example code
app\Http\Controllers\UserController.php
<?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; use App\Models\User; class UserController extends Controller { /** * Show the profile for a given user. * * @param int $id * @return \Illuminate\View\View */ public function show($id) { return view('user.profile', [ 'user' => User::findOrFail($id) ]); } }
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Trying to access array offset on value of type null error in laravel
- How to set column as primary key in Laravel model
- Command to create MySQL Docker image and access the MySQL command-line interface (CLI) within a running Docker container
- Update record after find method in lavavel
- How to create pivot table in laravel using migration
- How to check if user has created any post or not in laravel
- Count all and get 10 records after where condition in laravel
- Redirect to previous page or url in laravel
- How to insert multiple rows in mysql using loop in laravel?
- Session Doesn't Work on Redirect
- How to return error message from controller to view in laravel
- Create record with unique slug in laravel
- How to create new user without form submission in laravel
- Convert multidimensional array to single array in Laravel
- Use of undefined constant laravel
- Get last week data in Laravel
- FirstOrCreate() Not Inserting Model
- How to randomly get the user id from users table in laravel
- How to send email in laravel
- How to check relationship is loaded or not in Laravel
- On delete set foreign id column value null using migration in laravel 8
- How to insert dynamic values to additional column with pivot column in pivot table on multiple records
- How to delete record in Laravel with ajax
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Include External CSS and JS file in Laravel