Found 52 Articles for Laravel

118 Views
Introduction GET parameters passing in Laravel by forms is used in many web applications. GET parameters are most often used to filter data or even keep a search query after page transitions and to pass some information among pages. Having a good understanding of how to properly pass GET parameters to Laravel forms makes data handling smoother for better user experience.In this tutorial, different ways of passing GET parameters to Laravel forms through the GET method, with some best practices and actual examples, are discussed. Problem Statement The default method of Laravel forms is POST. However, when it comes to ... Read More

83 Views
Introduction When building a Laravel application, managing routes efficiently is crucial. Laravel provides various methods to define routes, and two commonly used approaches for handling resourceful controllers are Route::resource and Route::controller. While both help manage routes in a structured way, they have key differences in how they define and handle requests.In this article, we will explore the differences between Route::resource and Route::controller with an easy-to-understand table and examples. Key Differences Feature ... Read More

100 Views
PHP is known as an older language that serves almost 60% of websites around the world. Due to its simplicity and stability, some popular web technologies are based on PHP, one of them being Laravel. Laravel is a well-known backend framework that provides developers with all the tools needed to build robust and secure web applications. Laravel is on the list of top web technologies and frameworks used to build web apps. Because it's a PHP based framework, it's easy to use and learn, which makes it a great choice for beginner level developers starting their journey into web development, ... Read More

2K+ Views
Blade is a template engine that helps you to build your view display in laravel. It also helps you to use php code inside the template. The blade templates are saved as filename.blade.php and are stored inside resources/views/ folder. To understand the above question let us create a view calling the blade template. Example 1 Inside routes/web.php I have created the following route that is calling the view hello with data ['mymsg' => 'Welcome to Tutorialspoint']. Route::get('hello', function () { return view('hello', ['mymsg' => 'Welcome to Tutorialspoint']); }); The hello.blade.php is inside resources/views folder − {{$mymsg}} ... Read More

5K+ Views
To get all the field values from the html form you can make use of the Request class. The class Illuminate\Http\Request; has to be included in your controller. Example 1 This example shows the student registration form and it has fields like name, email, age and address. Student Form @if (count($errors) > 0) @foreach ($errors->all() as $error) {{ $error }} @endforeach @endif Student Registration Name Email Age Address The StudentController class is as follows −

3K+ Views
To validate data you can make use of the Validation class. The validation helps to validate data as well as to display error messages to the user. Example 1 In the example below the make() method is used. The first argument is the data to be validated and the second is the rule applied on the data : name. $validator = Validator::make( array('name' => 'Disha'), array('name' => 'required|min:5') ); As per the above the name assigned is Disha. As per the rule the name is mandatory and the minimum characters required is 5. ... Read More

3K+ Views
To validate data you can make use of the Validation class. The validation helps to validate data as well as to display error messages to the user. To get the exact words to validate you can make use of Rule::in method available with laravel. Using Rule::in method whatever the values provided by this rule has to be matched otherwise it will fail. Example 1 working with Rule::in method To work with Rule::in method you need to include the class : use Illuminate\Validation\Rule; or use Rule; $input = [ 'category' => ['ABC', 'XYZ'], ]; Validator::make($input, [ ... Read More

11K+ Views
In laravel the routes are defined inside routes/ folder.The routes are defined inside web.php file. The file is created when the laravel installation is done. Laravel routes take in a URI and a closure function as shown below − use Illuminate\Support\Facades\Route; Route::get('/student', function () { return 'Hello Student'; }); The routes defined inside web/routes.php are assigned a web middleware group and they have session states and CSRF protection. You can also call your controller inside routes as shown below − use Illuminate\Support\Facades\Route; use App\Http\Controllers\StudentController; Route::get('student', [StudentController::class, 'index']); Following are the route methods you can make ... Read More

23K+ Views
CSRF stands for Cross-Site Request Forgeries. CSRF is a malicious activity performed by unauthorized users acting to be authorized. Laravel protects such malicious activity by generating a csrf token for each active user session. The token is stored in the user's session. It is always regenerated if the session changes, hence the token is verified for each session to make sure the authorized user is performing any task. Here is an example to get access to the csrf_token. To generate csrf token You can get the token in two ways. By using the $request→session()→token() By using the csrf_token() method ... Read More

7K+ Views
In Laravel, you can make use of the Hash facade module to work with passwords. It has bcrypt for helping you store your passwords securely. The Hash facade bcrypt() method is a powerful way to hash a password. It prevents malicious users from breaking the password generated using bcrypt(). The hashing details are available inside config/hashing.php. The default driver has bcrypt() as the hashing to be used. Hashing Passwords To work with Hash Facade you need to include the class: Illuminate\Support\Facades\Hash Example To hash passwords you can use the make() method. Here is an example of a hash password ... Read More