Laravel Auth: After-Registration Redirect to Previous (Intended) Page

Laravel Auth features a function to redirect logged-in user to the same page they were visiting before. So, for example, if you visit /posts, you get automatically redirected to /login and then enter your data successfully, Laravel will “remember” and redirect you back to /posts instead of default /home. But it doesn’t work with new user registration, let’s see how we can change it.

Imagine the scenario:

  • You visit /posts URL;
  • System uses ‘auth’ middleware and redirects you back to /login form;
  • But you don’t have a user yet, so you click Register and land on /register URL;
  • And then, after successful registration – you get redirected where? To default /home URL, or whatever is specified in $redirectTo property in RegisterController.

So, how to customize it and make Laravel “remember” previous page for registration, too? We will dive into how Auth works internally.

In fact, it already stores that information, we just need to use it.

If you dig deeper into the LoginController logic, it uses Trait AuthenticatesUsers.php from core Laravel’s /vendor folder. And it has this method:

public function login(Request $request) { // ... if ($this->attemptLogin($request)) { return $this->sendLoginResponse($request); } // ... }

Let’s dig deeper – what is sendLoginResponse()? Within the same Trait:

protected function sendLoginResponse(Request $request) { // ... return $this->authenticated($request, $this->guard()->user()) ?: redirect()->intended($this->redirectPath()); }

As you can see, it uses redirect()->intended() method. How does it work? Official Laravel documentation describes it like this:

The intended method on the redirector will redirect the user to the URL they were attempting to access before being intercepted by the authentication middleware.

Under the hood, its logic is in /vendor/laravel/framework/src/Illuminate/Routing/Redirector.php:

public function intended($default = '/', $status = 302, $headers = [], $secure = null) { $path = $this->session->pull('url.intended', $default); return $this->to($path, $status, $headers, $secure); } 

Now, let’s take a look at app/Http/Controllers/Auth/RegisterController.php, it also uses a Trait from the core:

trait RegistersUsers { use RedirectsUsers; // ... public function register(Request $request) { $this->validator($request->all())->validate(); event(new Registered($user = $this->create($request->all()))); $this->guard()->login($user); return $this->registered($request, $user) ?: redirect($this->redirectPath()); } 

Look at the last part of redirection. As you can see, it uses simple redirect(), without intended(). So this is the part we need to change.

But we can’t edit that directly in /vendor folder, what we do is we copy-paste the same Trait’s method into RegisterController, and change the redirection part:

class RegisterController extends Controller { use RegistersUsers; // ... /** * Handle a registration request for the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function register(Request $request) { $this->validator($request->all())->validate(); event(new Registered($user = $this->create($request->all()))); $this->guard()->login($user); return $this->registered($request, $user) ?: redirect()->intended($this->redirectPath()); } }

And, that’s it – now, after registration user will be redirected to the page they were visiting before ‘auth’ middleware restricted their access.

You can read more Auth “tricks” in these articles:

via Laravel Daily
Laravel Auth: After-Registration Redirect to Previous (Intended) Page

PHP Implode Example | PHP implode() Function Tutorial

PHP implode() Function Example

PHP Implode Example | PHP implode() Function Tutorial is today’s topic. The implode function in PHP is used to join the elements of an array with a string. The implode() function returns the string from the elements of the array. The function is binary-safe. The implode() function returns a string containing the string representation of all the array items in the same order, with a glue string between each element. We join the array elements with the string. Just like join() function, implode() function also returns the string formed from the elements of the array.

PHP Implode Example

If we have an array of elements, we can use the implode() function to join them all to form one string. See the syntax of PHP implode() function.

Syntax

implode(separator,array)

The separator parameter is optional and specifies what to put between the array elements.

The array parameter is required, and it is the array to join to the string.

See the following example.

<?php

// app.php

$frontend = ['Svelete','Angular','React', 'Vue'];
echo implode("|", $frontend);

See the below output.

PHP Implode Example

 

The implode() function accept its parameters in either order. However, for consistency with the explode() function, you should use the documented order of arguments.

One thing you can note that an array with one or no elements works fine. For example, see the code.

<?php

// app.php

$arrA = ["Asylum","House","Coven"];
$arrB = ["AHS"];
$arrC = [];

echo implode("|", $arrA)."\n";
echo implode("|", $arrB)."\n";
echo implode("|", $arrC);

See the below output.

PHP implode() Function Tutorial

 

The implode() function in PHP is easily remembered as “array to a string,” which means that it takes an array and returns a string. It rejoins any array elements and returns the resulting string, which may be put in a variable.

PHP implode() function on Associative Arrays

The implode function acts on array “values,” disregarding any keys. See the following example.

<?php

// app.php

$devs = ['1st' => 'CloudArchitecht',
        '2nd' => 'DevOps',
        '3rd' => 'DataScientists'];

echo implode(" | ", $devs)."\n";

See the below output.

PHP implode() function on Associative Arrays

 

The implode() function also be used for building tags or complex lists, like the following.

<?php

$elements = array('a', 'b', 'c');

echo "<ul><li>" . implode("</li><li>", $elements) . "</li></ul>";

Also, it is quite handy in INSERT statements.

<?php

 // array containing data
 $array = array(
  "name" => "Krunal",
  "surname" => "Lathiya",
  "email" => "krunal@appdividend.com"
);

// build query...
$sql  = "INSERT INTO table";

// implode keys of $array...
$sql .= " (`".implode("`, `", array_keys($array))."`)";

// implode values of $array...
$sql .= " VALUES ('".implode("', '", $array)."') ";

// execute query...
$result = mysql_query($sql) or die(mysql_error());

If you want to implode the array of booleans, you will get strange result. See the following code.

<?php

// app.php

var_dump(implode('', array(false, true, false, false, true)));

The output is following.

PHP Implode Example Tutorial

 

It is worth noting that if you call implode on the string rather than the array, you do not get your string back, you get NULL.

The implode() function returns a string

 

The null values are imploded too. You can use an array_filter() to sort out the null values.

<?php

$ar = array("krunal", null, "lathiya");

print(implode(',', array_filter($ar, function($v){ return $v !== null; })));

Finally, PHP Implode Example | PHP implode() Function Tutorial is over.

The post PHP Implode Example | PHP implode() Function Tutorial appeared first on AppDividend.

via Planet MySQL
PHP Implode Example | PHP implode() Function Tutorial

PHP Insights

PHP Insights

PHP Insights is a package by Nuno Maduro for instant PHP quality checks in your console.

As found in the project readme file, PHP Insights main features include:

  • Analysis of code quality and coding style
  • Beautiful overview of code architecture and it’s complexity
  • Designed to work out-of-the-box with Laravel, Symfony, and more
  • Contains built-in checks for making code reliable, loosely coupled, simple, and clean
  • Friendly console interface build on top of PHPCS, PHPLOC, and EasyCodingStandard

If you want to use PHP Insights on a Laravel project, an artisan command is provided to run insights:

php artisan insights [-v] 

When you run the command, you are provided an overview insights score spanning code, complexity, architecture, and miscellaneous (i.e., coding style and security). Below the overview is an interactive prompt to go over each scoring area in more detail:

I took PHP Insights for a test drive and was impressed with the ease of setup and use within a Laravel project, and the code is well structured to support any PHP project you might encounter now or in the future.

The project is under active development; the Readme highlights a few ways you can contribute to this project: writing custom Insights from scratch, adding a new insight from PHP CS Sniff, and creating or improving a preset of your favorite framework (here’s the Laravel preset).

At the time of writing, framework presets exist for Laravel, Symfony, and Yii.

Be sure to check out the How to Contribute section of the Readme for examples and details on how you can support this excellent open-source package.

You can learn more about this package, get full installation instructions, and view the source code on GitHub at nunomaduro/phpinsights.


Filed in: News


Enjoy this? Get Laravel News delivered straight to your inbox every Sunday.

No Spam, ever. We’ll never share your email address and you can opt out at any time.

via Laravel News
PHP Insights

The Laravel Security Checklist (Sponsor)

The Laravel Security Checklist (Sponsor)

At Sqreen, we’re on a mission to help developers build more secure applications. But security is hard. It’s not always obvious what needs doing, and the payoffs of good security are at best obscure. Who is surprised when it falls off our priority lists? We’d like to offer a little help.

We created a Laravel Security Checklist to provide some guidance and to cover the best practices on securing your Laravel applications. Here are 10 tips from the checklist to get you started: 

Code

  Filter and Validate All Data

Laravel’s Eloquent ORM uses PDO parameter binding to limit SQL injections. But Laravel also offers other ways to craft SQL queries. Regardless of where the data comes from, whether that’s a configuration file, server environment, GET and POST, or anywhere else, do not trust it. Filter and validate it!

Read more:

  Invalidate Sessions When Required

After any significant application state change, such as a password change, password update, or security errors, expire and destroy the session.

Read more:

  Store Passwords Using Strong Hashing Functions

Ensure that all passwords and other potentially sensitive data are hashed, using robust hashing functions such as bcrypt. Don’t use weak hashing functions, such as MD5 and SHA1. Laravel comes with a native hash mechanism using Bcrypt and Argon2. Use them!

Read more:

  Use Laravel’s built-in encryption

Laravel comes with a built-in encryption mechanism and we highly recommend you use that one instead of building your own. As of PHP 7.2, older encryption libraries have been deprecated, such as Mcrypt. However, PHP 7.2 supports the far better Libsodium library instead. If you want to use a different encryption library, take a look at Libsodium.

Read more:

Infrastructure

  Check Your SSL / TLS Configurations

Ensure that your server’s SSL/TLS configuration is up to date and correctly configured, and isn’t using weak ciphers, outdated versions of TLS, valid security certificates without weak keys, etc, by scanning it regularly.

Read more:

  Rate Limit Requests to Prevent DDoS Attacks

To stop users attempting to perform brute force login attacks and overwhelm your forms, use tools such as Fail2Ban to throttle requests to acceptable levels.

Read more:

  Log All The Things

Regardless of whether you’re logging failed login attempts, password resets, or debugging information, make sure that you’re logging, and with an easy to use, and mature package, such as Monolog.

Read more:

Protection

  Send All Available Security Headers

There are several security headers that you can use to make your websites and web-based applications more secure, for minimal effort. These include HSTS, X-XSS-Protection, X-Frame-Options, X-Content-Type-Options, and a Content Security Policy. Ensure that they’re being configured correctly and sent in your request responses.

Read more:

  Have a Content Security Policy

Whether you have a one page, static website, a large static website, or a sophisticated web-based application, implement a Content Security Policy (CSP). It helps to mitigate a range of common attack vectors, such as XSS.

Read more:

  Monitor your application security

Monitor your application security for suspicious behaviors and attacks. Knowing when your application is starting to get attacked is key to protect it before it’s too late.

Want to read the full checklist? Download your copy here!


Many thanks to Sqreen for sponsoring Laravel News this week.


Filed in: Sponsor


Enjoy this? Get Laravel News delivered straight to your inbox every Sunday.

No Spam, ever. We’ll never share your email address and you can opt out at any time.

via Laravel News
The Laravel Security Checklist (Sponsor)

Dealmaster: There’s a bunch of deals on Anker charging gear today

Today seems like a decent day to stock up on charging gear.
Enlarge /

Today seems like a decent day to stock up on charging gear.

Anker

Greetings, Arsians! The Dealmaster is back a bit earlier than usual this week to highlight a one-day sale that may be of interest to those in need of new charging gear. Amazon is currently discounting a number of wall chargers, battery packs, and charging cables from popular accessories maker Anker as part of its daily “Gold Box” discounts.

Anker runs these kind of peripheral deals frequently, often through discount codes, but most of what’s on sale here is at or near its lowest price to date. Here’s a quick rundown of the highlights:

  • The PowerPort Speed+ Duo wall charger is down to $19.49 from its usual $26. It comes with a 30W USB-C Power Delivery port, which is powerful enough to charge most new smartphones at max speed (with the appropriate cable) and can charge some ultra-thin laptops like Apple’s 12-inch MacBook. There’s a 12W USB-A port alongside that.
  • The black model of the PowerPort I desktop charger is down to $35 from its usual $50. This charger is more designed to live on a desk, but it also includes a 30W USB-C PD port along with four 12W USB-A ports. The whole things gets up to a maximum of 60W, so you won’t be able to get a full-speed charge from every port if you use them all at once. But at this price, it should still be versatile enough to be useful if you regularly have multiple devices to refill at once.
  • If you need new charging cords, a two-pack of the company’s MFi-certified Lightning cables is $15 instead of their usual $20, a three-pack of microUSB cables is $7.70 instead of their usual $11, and its braided USB-C cable is $9.50 instead of its usual $15. The first two items come with an 18-month warranty, while the USB-C cable comes with a lifetime warranty.

There are a few more deals beyond that, but these additional sales aren’t quite as enticing as the ones above. A pair of wireless chargers—one

a flat pad

, the other

a charging stand

—is similarly priced near all-time lows, but

we found the former to be outclassed

by a

competing pad from RAVPower

that is currently available for the same price and the latter maxes out at a slow 5W of power. Neither come with an AC adapter, either. If you can put up with the generally slower speeds of wireless charging as a whole, we think you can do better by paying up a little bit more.

Likewise, a trio of Anker’s power banks are also on sale: a 10,000mAh pack that’s $10 off at $26, a 15,600mAh pack that’s $12 off at $27.19, and a 20,000mAh pack that’s $18 off at $42. All of these are fine: they’re well-reviewed, reliable, and include 18-month warranties. If you’re just looking for a good chunk of capacity at a low price, they should do the job. But they all only have USB-A and microUSB ports. With more and more devices launching with support for USB-C fast charging, we’d prefer our next power bank to be a little more future-proof and include a USB-C PD port.

Per usual with Gold Box sales, all of the deals here will last until the end of the day or until the item in question sells out. Anker is something of a big name in this market for selling reliable accessories for relatively cheap, so if you want to stock up on chargers, you could do worse than some of the deals above. Either way, the Dealmaster will be back tomorrow with a larger deals roundup.

Note: Ars Technica may earn compensation for sales from links on this post through affiliate programs.

via Ars Technica
Dealmaster: There’s a bunch of deals on Anker charging gear today

PHP in 2019

PHP in 2019

Do you remember the popular "PHP: a fractal of bad design" blog post? The first time I read it, I was working in a crappy place with lots of legacy PHP projects. This article got me wondering whether I should just quit and go do something entirely different than programming.

Luckily for me I was able to switch jobs shortly thereafter and, more importantly, PHP managed to evolve quite a bit since the 5.* days. Today I’m addressing the people who are either not programming in PHP anymore, or are stuck in legacy projects.

Spoiler: some things still suck today, just like almost every programming language has its quirks. Many core functions still have their inconsistent method signatures, there are still confusing configuration settings, there are still many developers out there writing crappy code — because they have to, or because they don’t know better.

Today I want to look at the bright side: let’s focus on the things that have changed and ways to write clean and maintainable PHP code. I want to ask you to set aside any prejudice for just a few minutes.

Afterwards you’re free to think exactly the same about PHP as you did before. Though chances are you will be surprised by some of the improvements made to PHP in the last few years.

# TL;DR

  • PHP is actively developed with a new release each year
  • Performance since the PHP 5 era has doubled, if not tripled
  • There’s a extremely active eco system of frameworks, packages and platforms
  • PHP has had lots of new features added to it over the past few years, and the language keeps evolving
  • Tooling like static analysers has matured over the past years, and only keeps growing

Let’s start.

# History summarized

For good measure, let’s quickly review PHP’s release cycle today. We’re at PHP 7.3 now, with 7.4 expected at the end of 2019. PHP 8.0 will be the next version after 7.4.

Ever since the late 5.* era, the core team tries to keep a yearly release cycle, and have succeeded in doing so for the past four years.

In general, every new release is actively supported for two years, and gets one more year of "security fixes only". The goal is to motivate PHP developers to stay up-to-date as much as possible: small upgrades every year are way more easy than making the jump between 5.4 to 7.0, for example.

An active overview of PHP’s timeline can be found here.

Lastly, PHP 5.6 was the latest 5.* release, with 7.0 being the next one. If you want to know what happened to PHP 6, you can listen to the PHP Roundtable podcast.

With that out of the way, let’s debunk some common misconceptions about modern PHP.

# PHP’s performance

Back in the 5.* days, PHP’s performance was… average at best. With 7.0 though, big pieces of PHP’s core were rewritten from the ground up, resulting in two or three times performance increases.

Words don’t suffice though. Let’s look at benchmarks. Luckily other people have spent lots of time in benchmarking PHP performance. I find that Kinsta has a good updated list.

Ever since the 7.0 upgrade, performance only increased. So much that PHP web applications have comparable — in some cases better — performance than web frameworks in other languages. Take a look at this extensive benchmark suite.

Sure PHP frameworks won’t outperform C and Rust, but they do quite a lot better than Rails or Django, and are comparable to ExpressJS.

# Frameworks and ecosystem

Speaking of frameworks: PHP isn’t just WordPress anymore. Let me tell you something as a professional PHP developer: WordPress isn’t in any way representative of the contemporary ecosystem.

In general there are two major web application frameworks, and a few smaller ones: Symfony and Laravel. Sure there’s also Zend, Yii, Cake, Code Igniter etc. — but if you want to know what modern PHP development looks like, you’re good with one of these two.

Both frameworks have a large ecosystem of packages and products. Ranging from admin panels and CRMs to standalone packages, CI to profilers, numerous services like web sockets servers, queuing managers, payment integrations; honestly there’s too much to list.

These frameworks are meant for actual development though. If you’re in need of pure content management, platforms like WordPress and CraftCMS are only improving more and more.

One way to measure the current state of PHP’s ecosystem is to look at Packagist, the main package repository for PHP. It has seen exponential growth. With ±25 million downloads a day, it’s fair to say that the PHP ecosystem isn’t the small underdog it used to be.

Take a look at this graph, listing the amount of packages and versions over time. It can also be found on the Packagist website.

Besides application frameworks and CMSs, we’ve also seen the rise of asynchronous frameworks the past years.

These are frameworks and servers, written in PHP or other languages, that allow users to run truly asynchronous PHP. A few examples include Swoole, Amp and ReactPHP.

Since we’ve ventured into the async world, stuff like web sockets and applications with lots of IO have become actually relevant in the PHP world.

There has also been talk on the internals mailing list — the place where core developers discuss the development of the language — to add libuv to the core. For those unaware of libuv: it’s the same library Node.js uses to allow all its asynchronicity.

# The language itself

While async and await are not available yet, lots of improvements to the language itself have been made over the past years. Here’s a non-exhaustive list of new features in PHP:

While we’re on the topic of language features, let’s also talk about the process of how the language is developed today. There’s an active core team of volunteers who move the language forward, though the community is allowed to propose RFCs.

Next, these RFCs are discussed on the "internals" mailing list, which can also be read online. Before a new language feature is added, there must be a vote. Only RFC with at least a 2/3 majority are allowed in the core.

There are probably around 100 people allowed to vote, though you’re not required to vote on each RFC. Members of the core team are of course allowed to vote, they have to maintain the code base. Besides them, there’s a group of people who have been individually picked from the PHP community. These people include maintainers of the PHP docs, contributors to the PHP project as a whole, and prominent developers in the PHP community.

While most of core development is done on a voluntary basis, one of the core PHP developers, Nikita Popov, has recently been employed by JetBrains to work on the language full time. Another example is the Linux foundation who recently decided to invest into Zend framework. Employments and acquisitions like these ensure stability for the future development of PHP.

Besides the core itself, we’ve seen an increase in tools around it the past few years. What comes to mind are static analysers like Psalm, created by Vimeo; Phan and PHPStan.

These tools will statically analyse your PHP code and report any type errors, possible bugs etc. In some way, the functionality they provide can be compared to TypeScript, though for now the language isn’t transpiled, so no custom syntax is allowed.

Even though that means we need to rely on docblocks, Rasmus Lerdorf, the original creator of PHP, did mention the idea of adding a static analysis engine to the core. While there would be lots of potential, it is a huge undertaking.

Speaking of transpiling, and inspired by the JavaScript community; there have been efforts to extend PHPs syntax in user land. A project called Pre does exactly that: allow new PHP syntax which is transpiled to normal PHP code.

While the idea has proven itself in the JavaScript world, it could only work in PHP if proper IDE- and static analysis support was provided. It’s a very interesting idea, but has to grow before being able to call it "mainstream".

# In closing

All that being said, feel free to still think of PHP as a crappy language. While the language definitely has its drawbacks and 20 years of legacy to carry with it; I can say in confidence that I enjoy working with it.

In my experience, I’m able to create reliable, maintainable and quality software. The clients I work for are happy with the end result, as am I.

While it’s still possible to do lots of messed up things with PHP, I’d say it’s a great choice for web development if used wise and correct.

Don’t you agree? Let me know why! You can reach me via Twitter or e-mail.

via Laravel News Links
PHP in 2019

Wrenching Hero Installs $120 Lawnmower Engine Into Dodge Ram Pickup

The only gasoline internal combustion engines that most people have in their households are either in cars or lawnmowers. That naturally leads to the thought: What if you took the tiny mower motor and installed it into an automobile? That’s what one young intrepid YouTuber did, and the results are glorious.

My coworker Jason Torchinsky and I have been talking about installing a pull-start lawnmower engine into a car for years now, but it looks like YouTuber Carson Duba has beaten us to the punch. And he appears to have done quite a nice job:

What we’re looking at here is an early 1980s Dodge Ram 50 powered by a 6.5 horsepower, 8.1 ft-lb overhead-valve single-cylinder engine sold at Harbor Freight for $120. The tool store, you will be surprised to know, does not actually list “automobile” as an application for this motor. Here’s the full list from the store’s website:

pressure washers, cement mixers, compressors, mowers, log splitters, vacuums, tillers, water pumps, chipper/shredders, generators, blowers

The Dodge had apparently been sitting in the young wrencher’s friend’s yard for a while, so the friend just gave it away. Carson Duba decided to have some fun with it, stripping out the old motor, leaving not much more than the steering intermediate shaft and brake master cylinder. He then built a platform that ties into the original engine mounts, and that carries the single-cylinder engine.

That engine, which can slide on the platform thanks to slotted holes, has a centrifugal clutch on its output shaft, which sends power to a five-speed manual transmission via a sprocket and a chain. To get a 60-tooth sprocket on the transmission end, the YouTuber welded a shaft to the transmission input shaft (unsurprisingly, it was difficult to weld it perfectly straight), and then made a bracket so that the shaft could ride on a bearing (this bracket ties into a custom mount that holds up the front of the transmission). The big sprocket sits on the end of that shaft, and the tension of its chain is set by sliding the motor along the slotted holes in the platform.

The whole build is far more elegant than I expected for something as silly as a lawnmower in a junky old truck. The choke is hooked up to a nice slider on the dash, the original cable running from the gas pedal actuates the tiny engine’s throttle, and there’s a fairly nicely-packaged pull cord that goes through the fender, with a handle in the wheel housing that starts motor. A simple kill switch on the dash cuts it off.

The young mechanic even made his own door panels using material from a shower, and he demonstrates in the video that the truck works in both reverse and in a forward gear, even if it only drives about 20 MPH.

h/t: Kyle!

via Gizmodo
Wrenching Hero Installs $120 Lawnmower Engine Into Dodge Ram Pickup

Favourite Laravel packages I always install

I thought it might be helpful for me to share a handful of packages which I find myself installing whenever I start a new Laravel application. Let me know if there are any missing!

Laravel Debug bar

barryvdh/laravel-debugbar (Github / Packagist)

Probably the first package I install in every Laravel project is the laravel Debug bar by Barry vd. Heuvel. With over 13 million installes I am not the only person who thinks this is an amazing package. You get a bar at the bottom of the browser window which will show you queries, information about the current Route, the currently loaded views, events and the Laravel version and Environment. And that’s just s small list of the things you can use it for.

composer require barryvdh/laravel-debugbar --dev

Laravel Telescope

laravel/telescope (Official Laravel Docs / GitHub / Packagist)

A very powerful ‘telescope’ into everything that your application is doing. I have only recently started to look at this but it’s been a great help for a recent application we have been working on.


Laravel IDE Helper

barryvdh/laravel-ide-helper (GitHub / Packagist)

A no brainer for anyone who uses PHPStorm. It will basically build some meta files fo the IDE to use which will help with all sorts of magic.

composer require --dev barryvdh/laravel-ide-helper php artisan clear-compiled php artisan ide-helper:meta php artisan ide-helper:generate

Laravel Query Detector

beyondcode/laravel-query-detector (GitHub / Packagist)

The Laravel N+1 query detector helps you to increase your application’s performance by reducing the number of queries it executes. This package monitors your queries in real-time, while you develop your application and notify you when you should add eager loading (N+1 queries). (Taken directly from the Readme)

composer require beyondcode/laravel-query-detector --dev php artisan vendor:publish --provider=BeyondCode\QueryDetector\QueryDetectorServiceProvider 

PHP Coding Standards Fixer

friendsofphp/php-cs-fixer (GitHub / Packagist)

I have been a huge fan of PSR-2 for a long time and if you have ever worked on a project with me you know I can be a sucker about PR’s with code style errors/issues. PHPStorm has a build in Code Style fixer and there are a number of other ways you can set up automatic code style fixing but I prefer this method. I tweak a few things in the config so that I can match my own specific style. I have included a .php_cs config file below so you can use this if you wish. I also use the Makefile as a little helper so that I can run make fix from my project root in a terminal.

I highly recommend you make use of this package locally but if you want to look at automating this and other Laravel specific code styles like making sure you are doing things “The Laravel Way’ then Check out Laravel Shift

composer require --dev friendsofphp/php-cs-fixer make test make fix

Laravel UUID

jamesmills/eloquent-uuid (GitHub / Packagist)

A Laravel Eloquent Model trait for adding and using a uuid with models. The trait listens to the creating event. It generates a new UUID and saves it in the uuid column on the model.

I personally like adding UUID’s to every entity in my application. There are the odd occurrences which I don’t do this. The main reason is that I find they much nicer to work with when it comes to URL’s and API’s. You can hide the auto-increment ID’s from the public eye and I personally just think they look and work better.

composer require jamesmills/eloquent-uuid

Just add the package and make sure your Entity/Model uses theHasUuidTrait. When you save the model then a UUID will automatically be added.

<?php namespace App; use JamesMills\Uuid\HasUuidTrait; class User extends Eloquent { use HasUuidTrait; }

Laravel Timezones

jamesmills/laravel-timezone (GitHub / Packagist)

Laravel Timezones package An easy way to set a timezone for a user in your application and then show date/times to them in their local timezone. I think this is pure magic!

I wrote a blog post specifically about the Laravel Timezones package where I go into a little more detail about why and how to use this package.

I don’t install this in every application but I have found that almost all of my applications have needed to show times and dates to a user in their specific timezone so I usually just install it at project setup so I have it there when needed.

composer require jamesmills/laravel-timezone // This will add a timezone column to your users table. php artisan migrate

It has a number of helpful features like blade directives

@displayDate($post->created_at) // 4th July 2018 3:32:am

Related

via Laravel News Links
Favourite Laravel packages I always install

Two Laravel Developers Building SaaS – SaaS Reality

The beginning…

We are two experienced developers and entrepreneurs who are sharing our journey as we build, launch and run SaaS businesses.

Join us, Simon and Dean, as we share our ‘accountability’ updates with the world.

Come along with us through the highs and lows as we talk openly about the challenges and triumphs of running an online SaaS business.

In this first episode you get to meet the hosts (us):

Simon, the young energetic Dad, already a successful SaaS founder with his Snapshooter.io product is scratching his own itch and building Automaily.

Dean, a survivor of the pre-internet corporate IT world and an ex CTO/Technical Director of a 7 figure web agency brings his experience and maturity of the enterprise to the SaaS world.

About Episode 1:

In this, our first episode, you’ll discover why we started this podcast and why we are sharing our journey with you.  Why we think this podcast is needed and who inspired us.

About Automaily:

Automaily is a churn busting and dunning automation tool with fully configurable workflows designed to help you recover lost and churned revenue.  

It also takes care of all the tedious and boring follow up emails when chasing down failed payments.

About CloudInsights.app

CloudInsights is tackling a hard problem, how to reduce your AWS bill and save time and money.

Dean’s product scans your AWS infrastructure and analyses your costs and usage data. It identifies unused, under-utilised and forgotten servers and resources.

With this knowledge you can right-size, shut down or refactor the troublesome parts of your Amazon Web Services infrastructure to save money and reduce your support and DevOps overheads.

Links:

People and podcasts mentioned during the episode and who inspired this podcast

via Laravel News Links
Two Laravel Developers Building SaaS – SaaS Reality

Laravel Google Translate

Laravel Google Translate

Laravel Google Translate is a package that provides an artisan console command to translate your localization files with the Google translation API. You can either leverage stichoza/google-translate-php without an API key or configure your Google Translate API key.

The console command php artisan translate:files walks you through some prompts to determine how to proceed with your translations files:

Future goals of this package include handling vendor translations, a web interface, and adding other translation APIs such as Yandex, Bing, etc.

You can learn more about this package, get full installation instructions, and view the source code on GitHub at tanmuhittin/laravel-google-translate.


Filed in: News / packages


Enjoy this? Get Laravel News delivered straight to your inbox every Sunday.

No Spam, ever. We’ll never share your email address and you can opt out at any time.

via Laravel News
Laravel Google Translate