background preloader

Tips & Tricks

Facebook Twitter

WherePivot and WherePivotIn - additional filters for many-to-many relationships - Laravel Daily. Recently I’ve found a small detail in Laravel documentation which I want to share with you.

WherePivot and WherePivotIn - additional filters for many-to-many relationships - Laravel Daily

Apparently, it’s possible to filter pivot tables additionally, if needed. Let me show you how. A PHP 7 / Laravel package to create slugs - murze.be. Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

A PHP 7 / Laravel package to create slugs - murze.be

You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Then sign up now! Spatie, the company where I work, recently released a Laravel package called laravel-sluggable. It automatically creates unique slugs when saving a model. To install the package you just need to put the provided Spatie\Sluggable\HasSlug-trait on all models that have slugs. This is the result when saving an Eloquent model. [SOLVED] how to convert after upload image to base 64 in laravel to save in db? - Laravel.io - The Laravel Community Portal. Quick Tip: The Convenient Magic of Eloquent Observers. If you’ve used Eloquent on medium to large projects before, you may have encountered a situation where you want to take action when something happens to your models.

Quick Tip: The Convenient Magic of Eloquent Observers

Eloquent provides a convenient way to do so. The Observer Pattern The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. – Wikipedia In our case, Eloquent models can notify us about changes on a given model. Model Events Eloquent provides a handful of useful events to monitor the model state: creating, created, updating, updated, deleting, deleted, saving, saved, restoring, restored. Notice the “ing/ed” difference. creating: Called before saving the new member.created: Called after saving the member.

Eloquent also fires similar events that we can listen for. Event::listen("eloquent.created: App\\Member", function(Member $member) { }); Overriding Laravel Elixir Configs. Laravel Elixir is fantastic for your Laravel projects and it comes with defaults that “just work” within a Laravel application.

Overriding Laravel Elixir Configs

It works so well that I like to use it for managing all my asset processing even in apps that are not on Laravel. As an example, I wanted to create a new WordPress theme and found a theme scaffolding system called underscores which comes with SASS files but not gulp. I decided this would be a good overview on how to setup Elixir to work with uncommon structures. Create your theme. GitHub - leeovery/wordpress-to-laravel: Provides means to sync Wordpress posts to your Laravel DB in order to use Laravel as the front-end to your WP blog (cos lets face it - WP templates suck ass) Laravel Collections Make PHP Development Awesome - Activate Saga. Laravel provides a lot of amazing tools out-of-the-box and collections are one of them.

Laravel Collections Make PHP Development Awesome - Activate Saga

The collection class within Illuminate\Support is basically a wrapper that allows you to work with and manipulate arrays of data. One of the things I’ve noticed that the class uses PHP’s default array methods such as, array_sum, array_map, array_keys, etc. within the map method, you can see that it utilizes array_map and array_keys: /** * Run a map over each of the items. * * @param callable $callback * @return static */public function map(callable $callback){ $keys = array_keys($this->items); $items = array_map($callback, $this->items, $keys); return new static(array_combine($keys, $items));} Conditional Eloquent Where Clauses - Laravel Tips 'N Tricks. Hi there, I didn’t wrote for a while, but today I find a very good Laravel Eloquent feature to work with – Conditional Clauses.

Conditional Eloquent Where Clauses - Laravel Tips 'N Tricks

Think of each Eloquent model as a powerful query builder allowing you to fluently query the database table associated with the model. So, basically you can use every Query Builder methods in your Eloquent model. You can read about conditional clauses here: But why it is important and why you need it? Bhaskar, Author at way2php.com.

Contact Form

Raveren/kint: Kint - a powerful and modern PHP debugging tool. Welcome to the LaraBrain - Welcome to the LaraBrain - Forcing Laravel to Treat a Database Column as a Date. Committed to the LaraBrain by: wjgilmore (@wjgilmore) at March 9, 2016 2:43 pm Laravel will automatically treat user-defined timestamps as dates however there is an easy fix On a recent project we wanted to track user's subscription renewal dates within the users table, and so defined a TIMESTAMP column named subscription_renews_at.

Welcome to the LaraBrain - Forcing Laravel to Treat a Database Column as a Date

This works as one would expect in terms of assignment: How to add Tagging to your Laravel App. In recent years, tagging systems have become a popular way of categorizing items, and you can find them in almost every app.

How to add Tagging to your Laravel App

From blog posts to todo lists, they all have tagging implementations. Let’s look at how easy integrating a tagging system is in a Laravel app. In the Laravel Links app I created a few weeks back I decided to add tagging to the links and what follows is instructions for setting it up. Installing a Tagging package The community has created several tagging packages, and you will need to research which one suits your use case. I choose the Laravel Tagging package by rtconner, and the installation is simple. First require the package:

Search - Scout

Laravel Quick Tip: Model Route Binding. One of the great things that Laravel provides is the easy to use routing component.

Laravel Quick Tip: Model Route Binding

It offers simple URLs, parameters, grouping, naming and event guarding route groups, to name a few of the different options. Let’s pretend we have a list of categories in a database, and the admin can manage categories from the back end. Here’s how your routes file should look like. Inside your CategoriesController class, you’ll have the seven resource methods. Inside the edit action, we should check if the category being edited exists in the database, otherwise we redirect back with an error message. Model Binding This is the usual way of doing it, but Laravel also has a nicer way of optimizing this repetitive task called route model binding. Build search functionality with Laravel Scout and Vue.js. Today, we are going to learn how to build a simple search functionality using Laravel Scout and Vue.js.

Build search functionality with Laravel Scout and Vue.js

Laravel Tutorials. View your routes through the browser with the Pretty Routes package. One nice Laravel feature is its routing, by visiting your routing file, you can get an eagle eye view of your application and a map that shows which URL is corresponding to which file. By default, Laravel provides a handy Artisan command php artisan route:list that can be used to list your routes in a table in your terminal, Pretty Routes is a third party package that aims to offer an alternative way to view the routes through the browser. Pretty Routes Installation First, install Pretty routes through Composer: composer require garygreen/pretty-routes Then add its Service provider in config/app.php: Prettier (and more helpful) Error Pages in Laravel 5.2 & 5.3+ - DevMarketer.

Looking for the code? Click Here to Scroll Down. You might remember back to the beginning of the “How to Build a Blog with Laravel 5” series I did a while back when we launched our page for the first time. I went on a rant live on camera about how much I hate the new Laravel 5 error pages. I got many comments about how passionate my hatred was, but I still stand by my reactions. Simon Jensen - Page 1 - Modern blog about coding. How to build a simple chat app with Laravel and Vue. What is Laravel Echo First of all.. what is Laravel Echo? Laravel Echo is a Javascript library that makes it painless to subscribe to channels and listen for events broadcast by Laravel.

Dependencies you have ti install First of all, you need to install these packages to get up and running with Laravel Echo / Broadcasting events. You may install Echo via the NPM package manager.

IDE Helper Generator

Persistent settings. Session Flash. Admin Auth. User Email Verification. GitHub - spatie/laravel-blade-javascript: A Blade directive to export variables to JavaScript. Browsing Most Recent Laravel Tricks. GitHub - Brotzka/laravel-dotenv-editor: A Laravel package for editing the .env file dynamically. Tracking If a User Is Currently Online in Laravel (the easy way) - Erik Belusic. Today I was tasked with adding a little green dot next to a username, denoting if they are online or not, on a user profile page, in a Laravel app. My first thought was that we were going to need to spin up a node.js server and track of active socket connections for each user. Then with the currently logged in users socket, we can update online status in real time!

The only issue is that this was a little bit over the top for our current requirement, and was not completely necessary until we have features that require up to the second accuracy such as real-time chat. A colleague pointed out that for the current need, the way that MySpace used to handle the “online” feature may be sufficient. To the best of our knowledge, the way that MySpace used to display if a user was online or not was based on their last activity on the site.

Let’s just add a column to the users table for that user’s last activity, and update that on every page request. We have a plan, so let’s get into the code! Browsing Most Recent Laravel Tricks. Laravel API 101. The VarDumper Component. Summernote - Super Simple WYSIWYG editor. Rochal/jQuery-slimScroll. PACE — Automatic page load progress bars.

GitHub - onokumus/metisMenu: A jQuery menu plugin. Laravel Intervention Summernote Editor to get upload File(image) URL instead of Base64. Sometime you upload image in database from summernote input text editor directly then you will ever notice then image upload into database in format of Base62. Upload in Base62 format is not the right way because there are number of characters that represent binary data in an ASCII string format. I will tell you here how you can get image url and how can you store image path in database instead of Base64 string. Use "intervention/image": "dev-master" package to work with image handling. So first update composer to include library of intervention image. After update composer, add service provider in the $providers for this package.

Intervention\Image\ImageServiceProvider::class. jQuery File Upload Demo. Proengsoft/laravel-jsvalidation for Laravel. Laravel Javascript Validation package allows to reuse your Laravel Validation Rules, Messages, FormRequest and Validators to validate forms automatically in client side without need to write any Javascript code or use HTML Builder Class. Dunebook - Tutorials for laravel , php , Angularjs & javascripts. Doing Best Practices in Laravel. Browsing Most Recent Laravel Tricks. Ajax Upload and Resize an Image with PHP. Today I am presenting the most important social networking feature called ajax upload and resize an image without refreshing the page using jquery and PHP. This tutorial a continuation of my previous post, I just included image re-sizing function for different dimensions.

It is very useful for your web project that saves lots of hosting space and bandwidth limit. Take a quick look at the live demo. Download Script Live Demo The tutorial contains three folders called js,includes and uploads with PHP files. includes -- getExtension.php -- compressImage.php js -- jquery.min.js -- jquery.form.jsuploads index.php ajaximageupload.php db.php Javascript Code$("#photoimg").live('change',function(){})- photoimg is the ID name of INPUT FILE tag and $('#imageform').ajaxForm() - imageform is the ID name of FORM. <script type="text/javascript" src=" type="text/javascript" src="jquery.form.js"></script><script type="text/javascript"> $(document).ready(function() { }); </script> <? <?