• Home
  • PHP
  • MySQL
  • Laravel
  • Demos
  • HTML
  • jQuery
  • Framework
  • Request Tutorial
PHP Lift
  • Home
  • Demos
  • Advertisement
PHP Lift
  • Home
  • PHP
  • MySQL
  • Laravel
  • Demos
  • HTML
  • jQuery
  • Framework
  • Request Tutorial
  • Follow
    • Facebook
    • Twitter
    • Google+
    • Pinterest
    • Youtube
    • Instagram
    • RSS
Useful Laravel functions and methods, Part-1
Home
Framework

Useful Laravel functions and methods, Part-1

November 3rd, 2025 Ivan Dimov Framework, PHP 0 comments

Facebook Twitter Google+ LinkedIn Pinterest

Laravel is one of the best PHP Framework so we are going to show you some cool functions and methods in this article I hope you like it.

dd($var) – This will print out beautifully its input.

request()->input(“parameterName”) – this method works with both GET and POST parameters and allows you to get the value of the given parameter.

view(“viewPath”, parametersArray) – the view function can be used as a return value within a controller to display a view (Blade/HTML/PHP template).

Session::flash(“name”, “msg”) – sets a session message on the next page render that disappears afterward.

request()->all() – returns an array of all user inputs

redirect()->back() – redirects back to the previous page that the user visited

redirect()->back()->withInput() – redirects back to the previous page that the user visited and passes back the inputs/parameters from this page.

redirect()->back()->with(“msgSuccess”, “The chosen articles were deleted.”); – you can pass arbitrary variables to the redirection; they might be stored in Session.

redirect(“root/relative/path”) – redirects to the given path

Session::get(‘sessionProperty’) – returns the value of the given session property

Database utilities

DB::table(‘tableName’) – you can use the DB class to interact with any database table within your established database connection. Once you select a table, you can chain methods to refine your query.

->select(‘blog.*, MAX(blog.id)’) – this would select some specific columns from the chosen table

->leftJoin(‘authors’, ‘blog.author_id’, ‘=’, ‘authors.id’) – this would perform a left join of another table based on the given condition

->whereIn(‘authors.id’, array(1,2,3,6,7) – this would make a wherein query to select all authors whose id is one of the values in the given array.

->orderBy(‘authors.age’) – this would order the authors by their age.

->orderBy(‘authors.age’, “ASC”) – this would order the authors in ascending order, by their age. Two values are possible – asc for ascending order and desc for descending.

->get() – this would finalize the actual database query and return the matching results

->first() – if you are looking for just one result, you can use first() to get the first matching row, you can also use it instead of get() in that case.

->max(“id”) – this will return the highest value of the field.

->delete() – chaining this to a query will delete all matching rows from the selection that precedes it.

->where(“id”, “=”, 3) – this will select only the item that has an id column with the value of 3.

$validator = Validator::make($data, [

        'name' => 'required|unique:authors,name,' . $id

    ], [

        'required' => “The :attribute field is required”,

        'unique' => trans('admin::validation.unique')

    ]);

Validator::make will make a validator, you can later check if some inputs pass the validation or not by using $validator->fails() which will return a Boolean with a truthy value if the validation fails. The first argument is the array with fields (you can just pass it request()->all()), the second are the rules according to which the data needs to be validated and the third are the messages that will be returned by the validator in case a specific validation fails. In the messages, you can use :attribute to refer to the field name, the message will then convert it to the proper field’s name.

I hope you like this article please do subscribe to get more in future.

Facebook Twitter Google+ LinkedIn Pinterest
Next article 7 HTML attributes that you must learn today!
Previous article Working with dates in PHP and JavaScript

Ivan Dimov

Ivan is a student of IT, a freelance web designer/developer and a tech writer. He deals with both front-end and back-end stuff. Whenever he is not in front of an Internet-enabled device he is probably reading a book or traveling. You can find more about him at: http://www.dimoff.biz. facebook, twitter

Related Posts

Convert your website into a Desktop App for Windows, Mac, Linux Framework
November 5th, 2025

Convert your website into a Desktop App for Windows, Mac, Linux

Stripe Payment Gateway Charge Credit Card with PHP Example API
November 5th, 2025

Stripe Payment Gateway Charge Credit Card with PHP Example

How to Create a Custom Options Page in WordPress? PHP
November 4th, 2025

How to Create a Custom Options Page in WordPress?

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe
Get new posts by email:
Powered by follow.it
Advertisement
Like us
Recent Posts
  • WhatsApp chatbot in Python using Dialogflow.com
  • Convert your website into a Desktop App for Windows, Mac, Linux
  • Useful JavaScript globals
  • The Art of Debugging in Software Development: A Comprehensive Guide
  • Stripe Payment Gateway Charge Credit Card with PHP Example
Categories
  • API
  • Bootstrap
  • Bot
  • CSS
  • CSS 3
  • Database
  • Designing
  • Framework
  • Guide
  • HTML
  • HTML 5
  • JavaScript
  • jQuery
  • Laravel
  • MySQL
  • Node.js
  • oAuth
  • Payment
  • PHP
  • Python
  • Social
  • Tips
  • Web 3.0
  • WordPress
Weekly Tags
  • PHP
  • javascript
  • How to
  • laravel
  • css
  • HTML to PDF
  • jQuery
  • api
  • Web Development
  • MYSQL
  • About
  • Privacy Policy
  • Back to top
© PHPLift.net. All rights reserved.