How to display a specific word from a string in laravel
How to display a specific word from a string in laravel
In this session, we are going to try to solve the "How to display a specific word from a string in laravel" puzzle by using the computer language.
You can display the specific word from string by converting the string to an array and after that you can get the value of each array element by passing the key to the array.-
Display first word from name in laravel view after getting the name of user
//It will display the first name of user @php $userName = explode(' ', $user->name); @endphp <p>{{ ucfirst($userName[0]) }}</p>
This code snippet will help you to get the first word from the user name. Sometimes we have a full name in a single column field and we want to display the first name instead of surname then we can display the first name from the full name in the laravel view without changing the controller or model code in laravel.
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
- Send post data from controller to view
- Get products with number of orders in Laravel
- Get id of last inserted record in laravel
- How to get column names from 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
- Create record with unique slug in laravel
- How to remove P tag from CkEditor in Laravel?
- Ajax POST request in laravel
- Input file with max size validation in laravel
- Store logged in user details in session and display in view in laravel
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- How to check find method executed successfully in laravel
- How to add a key value pair to existing array in laravel
- How to run a specific seeder class in laravel
- Extract only time from datetime in laravel
- How to pass data to partial view file in laravel
- Display first n record from collection in laravel view
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- Undefined property: stdClass::$title
- Class 'App\Providers\Auth' not found
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- How to get user information using hootlex/laravel-friendships package in laravel
- Get the products list ordered by a user
- Print query in laravel