Get Last Character of String PHP
Code Wall
by Dan Englishby
2y ago
Getting the last character of a string with PHP is pretty simple, all you need is one line of code and your string that needs to be sliced. Let’s take a demonstration string such as ‘This is my string!’ We need to grab the last character from the string which of course would be the exclamation mark. For this task, substr() is the perfect function. PHP $string = "This is my string!"; $lastChar = substr($string, -1); echo $lastChar; // outputs ! So, the substr() function accepts a string and some numeric parameters to ensure the correct parts of the string are stripped out. In this case we u ..read more
Visit website
Laravel LDAP Authentication Tutorial Using Adldap2-Laravel
Code Wall
by Dan Englishby
3y ago
With todays available packages, harnessing the highly accessible and user-friendly functionality of LDAP authentication with a Laravel application couldn’t be any more streamlined. Follow the steps in this tutorial to get your Laravel app authenticating with windows active directory in around 15 minutes. First and foremost, we are going to utilize a specifically designed PHP package for this job, it’s named Adldap2-Laravel Secondly, before we proceed into the step-by-step guide, you are going to need three things as an absolute minimum. An LDAP server connection hostname An active account tha ..read more
Visit website
Generating Laravel Seeder Code With Excel
Code Wall
by Dan Englishby
3y ago
How many times have you been working on a project which comes with existing data sets? And, how many times have these data sets been sent to you in excel? Well, in this article, I will go through one of my quick, time-saving tricks that generates seeder code from excel data sets. I will use a sample data set and include the excel file to download so you can follow along. Alternatively, you can use your own data set, just ensure you change all field names to match your data set. First of all, let’s set the scene with the data set. The given data set Ok, let’s imagine you’ve been given a data se ..read more
Visit website
Best Javascript Chart Libraries for 2021
Code Wall
by Dan Englishby
3y ago
In 2018 I collated an in-depth article on the best data visualization and charting libraries available for JavaScript. In this new 2021 edition, I will be re-rounding up the best, latest, and up-and-coming charting libraries and going into detail about their chart type availability, features, and in addition, demonstrating various examples. For the record, this list isn’t in any particular order. 1. NVD3.js First and foremost is a library I’ve used frequently in industry and it never fails to please. NVD3 is a library that sits on top of the d3.js JavaScript library utilizing many of the usual ..read more
Visit website
4 Ways To Get The Laravel Version
Code Wall
by Dan Englishby
3y ago
Four? Yes, four, there are four different ways to get the version number of any Laravel project. In this article, each of the different methods will be demonstrated. Method 1 – Using php artisan We can always rely on the trusty old php artisan command and in this case, we can too! Load up the command line at the projects root directory, and execute the following command – php artisan --version For example, this for my project outputs the following – Laravel Framework 8.12.0 Method 2 – Checking the composer.json file Yep, sat minding its own business, is the version of your Laravel project, rig ..read more
Visit website
Get The Current URL In Laravel Controller & View
Code Wall
by Dan Englishby
3y ago
The Answer: Accessing the current URL can be done by making use of the global url variable that is accessible in Laravel controllers. It can be called directly or can be imported as a facade that is then used as an ordinary static class. The URL facade exposes all the same methods as the global url variable offers. See the following working examples to see how to get the current URL in both Laravel controllers and view files. Get The Current URL Within Controllers $currentUrl = url()->current(); // OR $currentUrl = URL::current(); To utilize the second method, ensure you add the followi ..read more
Visit website
How To Show Validation Errors In Laravel Views
Code Wall
by Dan Englishby
3y ago
Validation feedback messages are an invaluable addition to any CRUD style application. If your app allows users to create records that are stored in your database, then you will of course want to validate them before saving to the database. Laravel comes with methods to handle this and it comes with Laravel blade syntax that will display any validation errors to the user. There are two parts to ensuring that validation checks are carried out and reported into the view, make your way through the following steps to add validation errors to your view. Step 1 Ensure proper validation checks are be ..read more
Visit website
Rollback Transaction With Laravel Eloquent
Code Wall
by Dan Englishby
3y ago
Rolling back queries is always a safeguard for your data if there were to be any errors during database manipulation. For example, during the execution of multiple delete commands or similarly, a save command in use with an update use-case. Laravel comes out-of-the-box with the rollback functionality and is particularly very simple to use. The answer to rolling back eloquent queries is to use a static DB::transaction call, wrapped around your database execution code. This addition to your standard controller code looks like the following ‘wrapper function’. DB::transaction(function () use ($p ..read more
Visit website
Get The Max Date With Laravel Eloquent
Code Wall
by Dan Englishby
3y ago
Getting the max date with Eloquent is executed by simply using the max() operator to get the maximum date time stamp in any given data table. The following example assumes the date column we are looking at is named created_at, but replace it with your own if needs be. PHP $lastRecordDate = Product::all('created_at')->max('created_at')->toArray(); dd($lastRecordDate); Whilst this Eloquent query gets the maximum date available in the table, it actually gives us more information in the output, another magic gem in Laravel. Output If you want to print the date time, it would be a case of ..read more
Visit website
2 Ways To Get Latest Record By Date With Laravel
Code Wall
by Dan Englishby
3y ago
Laravel has a couple of ways in which to interrogate the database it’s linked to. In this tutorial, we will explore the four ways that the latest record (by date time) can be pulled out of any specified table. Whether you like to use Eloquent or raw SQL, this article will answer both use-cases. Method 1 Method one uses Eloquent and utilizes two important operators too pull out the latest record, sortByDesc and take. The sortByDesc method will take a date time stamp as it’s specified column, in this case, the created_at column. After this we instruct a limit of 1 using the take() operator, mean ..read more
Visit website

Follow Code Wall on FeedSpot

Continue with Google
Continue with Apple
OR