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
- Target class [admin] does not exist.
- How to get query string value in laravel
- Pass variable from blade to controller Laravel
- How to create event and listener in laravel ?
- The use statement with non-compound name 'DB' has no effect
- How to change default timestamp fields name in Laravel
- How to get date from created_at field in laravel
- Skip first n record and display rest records in laravel view
- How to generate .env file for laravel?
- Get last record from table in laravel
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- Datetime field in Laravel migration
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- Laravel get single row by id
- Laravel 9 route group with controller
- Undefined property: stdClass::$title
- Route prefix with auth middleware in laravel
- How to add active class to menu item in laravel
- Print last executed query in laravel
- Get count of filter data, while return a small set of records
- Docker important commands to run laravel application with docker
- How to send ID to another page in Laravel
- Split an Eloquent Collection by half in Laravel
- How to add background image to div using Tailwindcss, Vite in Laravel Environment
- Call to a member function pluck() on array