Laravel 5: Generating URLs to Named Routes With route Apr 14, 2018
The route helper function in Laravel generates URLs for named routes. It takes three parameters: the route name, optional parameters for the URL, and a boolean to indicate if a fully qualified URL should be returned. By default, the function returns a fully qualified URL. You can customize the resulting URL by adding data to the query string.
Laravel 5: Generating URLs With url Apr 14, 2018
The url helper function in Laravel is a versatile function that can be used to generate URLs to specific paths or return an instance of the URL Generator class. It can be used to generate arbitrary URLs and can also include router parameters in the generated URL. By supplying a true argument to the $secure parameter, you can generate secure URLs.
Laravel 5: Hashing Strings With bcrypt Apr 14, 2018
The bcrypt function takes a value and returns a hashed representation of that value. It can also accept an array of options that affect how the hash is computed. Each invocation of the function will produce a different result, even if the input remains the same. One of the available options is the rounds option, which controls the number of iterations used to generate the final hash. The default value for rounds is 10, and increasing the value will increase the time required to compute the hash.
Laravel 5: Logging Informative Messages With info Apr 14, 2018
The info helper in Laravel allows you to write an information entry into the log files. It takes a $message as a parameter and an optional $context array. The $context array can contain any data, even if it's not an array itself. The example provided demonstrates the usage of the info helper and shows what the logged output would look like. Additionally, the examples show equivalent methods calls that can be used to achieve the same result.
Laravel 5: Managing HTTP Cookies With cookie Apr 14, 2018
The cookie function in Laravel is used to create a new instance of the \\Symfony\\Component\\HttpFoundation\\Cookie class, or an instance of \\Illuminate\\Cookie\\CookieJar. When creating a cookie, the function returns an instance of \\Symfony\\Component\\HttpFoundation\\Cookie but does not send the cookie to the client. The function takes optional parameters such as the cookie's name, value, expiration time, path, domain, security, and more. You can also use the function to create HTTPS-only cookies.
Laravel 5: Notifying Server Side Clients of Events With broadcast Apr 14, 2018
The broadcast helper function in Laravel is similar to the event helper function, but provides greater control over which client-side subscribers receive the event notification. It returns an instance of "Illuminate\Broadcasting\PendingBroadcast". In the example provided, when broadcasting over public channels, there is no advantage to using the broadcast helper function over the event helper function. However, when using private channels, the broadcast function allows excluding the currently authenticated user from receiving the event notification. Other than this difference, there is no significant distinction when using the broadcast helper function over the event helper function.
Laravel 5: Performing HTTP Redirects With redirect Apr 14, 2018
The redirect helper function in Laravel is a useful helper function that simplifies the task of returning HTTP redirects from controller actions or routes. It has a signature that includes parameters for the target URL, HTTP status code, headers, and secure option. By default, when the target URL is null, the function returns an instance of "Illuminate\\Routing\\Redirector". The Redirector class has many methods to control user flow, such as back(), home(), and to(). To redirect to a specific path, you can pass the path as an argument to the redirect function or use the to() method of the Redirector instance. If you want to redirect to a secure URL, you can pass true as an argument for the $secure parameter. Additionally, you can supply extra headers by providing an argument for $status and $headers.
Laravel 5: Recover From Possible Exceptions With rescue Apr 14, 2018
The rescue function in PHP allows you to attempt the execution of an operation that may throw an exception. By providing a default value through the $rescue parameter, you can specify what value should be returned if the operation fails. Additionally, the rescue function can log the inner exception using the report helper function. This can be helpful for debugging and error handling purposes. An alternative to using rescue is the traditional try/catch control structure, which achieves the same goal but with slightly different syntax.
Laravel 5: Redirecting Users to the Previous Page With back Apr 14, 2018
The back helper function is used to create a redirect response to the user's previous location. It can be used to control the status code and headers of the response. The function returns an instance of "Illuminate\Http\RedirectResponse". The back method can be accessed using the Redirect facade or the redirect helper function. The status code and headers can be changed by providing arguments for the $status and $headers parameters respectively. An example of supplying extra headers is also shown.
Laravel 5: Reporting Application Exceptions With report Apr 14, 2018
The report function is used to report an exception to the application's exception handler. It invokes the report method of the application exception handler with the provided exception. To use it, simply call the report function and pass in the exception you want to report.
Laravel 5: Resolving Authentication Policies With policy Apr 14, 2018
The policy helper function retrieves a policy instance for a given class. It can be called with either a string or an object instance. If no policies have been registered for the class, an exception will be thrown. To use custom policies, they need to be mapped to their associated model class, typically within the AuthServiceProvider file. The policy helper function internally calls the getPolicyFor method on the authentication gate instance.
Laravel 5: Resolving Concrete Implementations From the Service Container With resolve Apr 14, 2018
The resolve helper function is used to resolve a class instance from the Service Container. This function can be used to resolve any dependency from the Service Container as long as its constructor parameter dependencies can be resolved. Unlike the app helper function, it does not allow parameters to be supplied to the Service Container when resolving the dependency. For example, the resolve function can be used to resolve Laravel's event dispatcher from the Service Container by calling resolve('events').
Laravel 5: Retrieving Environment Variables With env Apr 14, 2018
The env function in PHP is used to retrieve the value of an environment variable. It allows you to specify a default value to be returned if the variable is not set. The function automatically converts boolean string representations and null representations into their corresponding PHP values.