
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
- Use of undefined constant laravel
- Create record with unique slug in laravel
- Send id with route Laravel
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]
- Automatically remove records using Prunable trait in Laravel
- How to get last record from object collection in laravel
- Laravel clone model
- Touch parent updated_at in Laravel
- How to create new user without form submission in laravel
- Remove public from url in laravel project
- FirstOrCreate() Not Inserting Model
- The use statement with non-compound name 'Auth' has no effect
- Rename Pivot Table in Laravel
- PhpMyAdmin - Error The mysqli extension is missing
- How to get specific columns using Laravel eloquent methods
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- How to create project_user pivot table in laravel
- How to add script on specific view file in laravel while extending layout
- How to create projects method with belongstomany relationship in user model
- How to create and run user seeder in laravel
- How to avoid duplicate entries in pivot table in Laravel
- How to check find method executed successfully in laravel
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- Pagination in laravel
- Method Illuminate\Events\Dispatcher::fire does not exist