Content Source:
Vue JS and Laravel – The best performative combination for front-end and back-end
“Vue.js is a dynamic structure for building UIs”. Vue.js at its core is centered on the view layer just of an application, so integrating with different stages or existing applications is extremely simple. You can likewise utilize Vue.js all alone to manufacture modern single page applications.
Uses and Features of Vue.js
- Vue.js is extremely simple to use and has a substantially little learning curve than other frameworks.
- It has impacting features compared to others. Vue.js utilizes virtual DOM and that makes it extremely quick.
- On the off chance that you are working in a group with various engineers at that point don’t stress. Since Vue.js can without much of a stretch incorporate with other mainstream structures.
- Vue.js has many Built-in parts while it’s extremely lightweight.
Vue.js has got prominent reception, with many open source frameworks and enormous organizations embracing it for building up the front-end. Laravel, the leading PHP web framework, now comes with Vue.js integrated as the default front-end
Features of Laravel in a glimpse
- Caching
- Laravel Scout
- Composer
- Templates
- Libraries
- Direct Testing Option
Why should we use Vue.js with Laravel?
Event Driven Application on the Front-End
Applications on the web today are event-driven. Vue.js gives you a chance to assemble a full-scale application that is event-driven and has all activity totally handle on the frontend. They are built to guarantee clients have a consistent experience like they would if they utilized an application introduced on their PC.
Everything happens in front-end due to which the pages are not loaded again and again for any process to take place. This event-driven concept is a feature of Vue.js.
Reactive components constitute for an event-driven app
Given that it couples pleasantly with Laravel, you will just need to make a couple of requests for information from your Laravel application and roll out UI improvements by exchanging components without reloading the page.
One can trigger UI changes that are seamless with your Vue.js frontend, which in turn gives users an incredible experience. Given Vue.js speed and execution, this happens quick and easily without taking up such a large amount of your PC resources.
Build complex frontend pages
When you make your application with Vue.js components, every component’s conditions are consequently tracked amid its render, so the framework knows decisively which part is to be updated. This makes all updates to the DOM utilize negligible assets, along these lines enhancing the general application proficiency.
Vue.js utilization of a one-way data binding model also makes state management easier in complex applications.
Single-Page Apps
Single Page Applications are the best in the most recent decade. It opens up an application to a more extensive group of users than previously.
The whole application resources get stacked once everything that your application does as the client connects with it is asking for information which commonly requires low data transmission to fulfill a request.
Easy to learn and use
Vue.js is not at all hard to get into. You feel that you are composing plain JavaScript when you utilize Vue.js and you can make a basic application with plain JavaScript and it stays legitimate in Vue.js.
Another awesome thing about Vue.js is that your substantial HTML is additionally a legitimate Vue.js layout. You can keep your CSS outside or you can process it with JavaScript relying upon your application needs. You can likewise exploit checked styling, to apply style changes to a solitary segment on the fly without the change influencing different parts.
For more Information and to build a website using Laravel, Hire Laravel Developer from us as we give you a high-quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft“.
To develop the custom website using Vue.js, please visit our technology page
Eventy: WordPress-like Actions and Filters for Laravel
Eventy is a Laravel package by Tor Morten Jensen that brings WordPress-style actions and filters to your Laravel app.
This package has a lightweight API and makes it easy to build an action and filter system as found in WordPress. The action and filter system in WordPress is a powerful way to customize WordPress themes without modifying the template. For example, your users could easily tap into the <title></title>
tag (think wp_title
) to modify the way that title tags work without modifying the template.
Actions
Actions are code that you want to enable the ability to tap into code execution at a given point in your code.
Here’s the basic API for creating actions:
Eventy::action('my.hook', 'awesome');
The best place to add action listeners is in a service provider boot()
method:
public function boot() { Eventy::addAction('my.hook', function($what) { echo 'You are '. $what; }, 20, 1); }
The Eventy::addAction()
method accepts the action name, the callback, the priority, and the number of expected args. The lower the priority number, the earlier the execution.
Filters
Like WordPress filters, the Eventy library provides a filter method to modify passed values. Every time a filter is called it returns it’s value after running through various callbacks:
$value = Eventy::filter('my.hook', 'awesome');
The first argument is the filter name, and the second is the value. If no filter listeners are attached, the return value would be awesome
.
The method siguature is the same as actions, including the priority and number of expected arguments:
Eventy::addFilter('my.hook', function($what) { $what = 'not '. $what; return $what; }, 20, 1); // returns `not awesome`
You can even combine actions and filters together:
Eventy::addAction('my.hook', function($what) { $what = Eventy::filter('my.hook', 'awesome'); echo 'You are '. $what; });
Templates
Using the same examples from the project’s readme, here’s what the template syntax looks like for this package:
{{-- for example, `echo "awesome"` --}} @action('my.hook', 'awesome') You are @filter('my.hook', 'awesome')
For more Information and to build website using Laravel, Hire Laravel Developer from us as we give you high quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft“.
To develop custom website using Laravel, please visit our technology page.
- laravel-news.com
VuePress: A Vue-powered Static Site Generator
VuePress is a minimalistic Vue-powered static site generator from Evan You, the creator of Vue.js. It was built to support the documentation needs of Vue’s projects. By default, the generated theme comes optimized for technical documentation.
VuePress sites are an SPA, and during a build, a server-rendered version gets created by visiting each route. VuePress is powered by Vue, Vue Router, and Webpack. You also can use Vue inside of your markdown!
Getting Started with VuePress
You can quickly add documentation to an existing project writing in Markdown format. The following example is from the getting started section of the guide and serves as an example of how quickly you can get started:
# install as a local dependency yarn add -D vuepress # OR npm install -D vuepress # create a docs directory mkdir docs # create a markdown file echo '# Hello VuePress' > docs/README.md
While you are writing content, the browser gets updated in real-time, which is extremely helpful while building documentation.
Features
Vue components in .vuepress/components
are automatically registered as global, async components that can be used directly in your markdown documentation.
Markdown files are first compiled to HTML and passed on as a Vue component to vue-loader
, and you can use Vue interpolation and have access to site data:
{{ 5 + 5 }} {{ $page }}
VuePress enables custom theming through Vue single file components. You can create a custom theme at .vuepress/themes/Layout.vue
, and you can organize your theme however you want. You can use a custom theme from a dependency with the format of an NPM module vuepress-theme-xxx
, in the following example that would be vuepress-theme-cobalt
:
module.exports = { theme: 'cobalt' }
You can use Markdown extensions including YAML front matter, emoji support, Github-style tables, and custom blocks:
::: danger STOP Danger zone, do not proceed :::
Which might look something like the following with the default theme.
For more Information and to build website using Laravel, Hire Laravel Developer from us as we give you high quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft“.
To develop custom website using Laravel, please visit our technology page.
Content Source:
- laravel-news.com
Laravel Model Caching
You’ve probably cached some model data in the controller before, but here’s we like to show you a Laravel model caching technique that’s a little more granular using Active Record models.
Using a unique cache key on the model, you can cache properties and associations on your models that are automatically updated (and the cache invalidated) when the model (or associated model) is updated. A side benefit is that accessing the cached data is more portable than caching data in the controller, because it’s on the model instead of within a single controller method.
Here’s the gist of the technique:
Let’s say you have an Article
model that has many Comment
models. Given the following Laravel blade template, you might retrieve the comment count like so on your /article/:id
route:
<h3>$article->comments->count() {{ str_plural('Comment', $article->comments->count())</h3>
You could cache the comment count in the controller, but the controller can get pretty ugly when you have multiple one-off queries and data you need to cache. Using the controller, accessing the cached data isn’t very portable either.
We can build a template that will only hit the database when the article is updated, and any code that has access to the model can grab the cached value:
<h3>$article->cached_comments_count {{ str_plural('Comment', $article->cached_comments_count)</h3>
Using a model accessor, we will cache the comment count based on the last time the article was updated.
So how do we update the article’s updated_at
column when a new comment is added or removed?
Enter the touch method.
Touching Models
Using the model’s touch()
method, we can update an article’s updated_at
column:
$ php artisan tinker
>>> $article = \App\Article::first();
=> App\Article {#746
id: 1,
title: "Hello World",
body: "The Body",
created_at: "2018-01-11 05:16:51",
updated_at: "2018-01-11 05:51:07",
}
>>> $article->updated_at->timestamp
=> 1515649867
>>> $article->touch();
=> true
>>> $article->updated_at->timestamp
=> 1515650910
We can use the updated timestamp to invalidate a cache, but how can we touch the article’s updated_at
field when we add or remove a comment?
It just so happens that Eloquent models have a property called $touches
. Here’s what our comment model might look like:
<?php
namespace App;
use App\Article;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
protected $guarded = [];
protected $touches = ['article'];
public function article()
{
return $this->belongsTo(Article::class);
}
}
The $touches
property is an array containing the association that will get “touched” when a comment is created, saved, or removed.
The Cached Attribute
Let’s go back to the $article->cached_comments_count
accessor. The implementation might look like this on the App\Article
model:
public function getCachedCommentsCountAttribute()
{
return Cache::remember($this->cacheKey() . ':comments_count', 15, function () {
return $this->comments->count();
});
}
We are caching the model for fifteen minutes using a unique cacheKey()
method and simply returning the comment count inside the closure.
Note that we could also use the Cache::rememberForever()
method and rely on our caching mechanism’s garbage collection to remove stale keys. We’ve set a timer so that the cache will be hit most of the time, with a fresh cache every fifteen minutes.
The cacheKey()
method needs to make the model unique, and invalidate the cache when the model is updated. Here’s my cacheKey
implementation:
public function cacheKey()
{
return sprintf(
"%s/%s-%s",
$this->getTable(),
$this->getKey(),
$this->updated_at->timestamp
);
}
The example output for the model’s cacheKey()
method might return the following string representation:
articles/1-1515650910
The key is the name of the table, the model id, and the current updated_at
timestamp. Once we touch the model, the timestamp will be updated, and our model cache will be invalidated appropriately.
Here’s the Article
model if full:
<?php
namespace App;
use App\Comment;
use Illuminate\Support\Facades\Cache;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
public function cacheKey()
{
return sprintf(
"%s/%s-%s",
$this->getTable(),
$this->getKey(),
$this->updated_at->timestamp
);
}
public function comments()
{
return $this->hasMany(Comment::class);
}
public function getCachedCommentsCountAttribute()
{
return Cache::remember($this->cacheKey() . ':comments_count', 15, function () {
return $this->comments->count();
});
}
}
And the associated Comment
model:
<?php
namespace App;
use App\Article;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
protected $guarded = [];
protected $touches = ['article'];
public function article()
{
return $this->belongsTo(Article::class);
}
}
What’s Next?
We’ve shown you how to cache a simple comment count, but what about caching all the comments?
public function getCachedCommentsAttribute()
{
return Cache::remember($this->cacheKey() . ':comments', 15, function () {
return $this->comments;
});
}
You might also choose to convert the comments to an array instead of serializing the models to only allow simple array access to the data on the frontend:
public function getCachedCommentsAttribute()
{
return Cache::remember($this->cacheKey() . ':comments', 15, function () {
return $this->comments->toArray();
});
}
Lastly, we defined the cacheKey()
method on the Article
model, but you would want to define this method via a trait called something like ProvidesModelCacheKey
that you can use on multiple models or define the method on a base model that all our models extend. You might even want to use a contract (interface) for models that implement a cacheKey()
method.
Hire Laravel Developer from us, as we give you high quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft“.
To develop custom web app using Laravel, please visit our technology page.
Content Source:
- laravel-news.com
A Package for Laravel Blade Extension Classes
Laravel created a Blade Extension package that allows you to register Blade extension classes in the service container that automatically get registered with the Blade compiler. You can also easily create new Blade extension classes with the provided php artisan make:blade
command (auto-registered package commands FTW).
The concept isn’t revolutionary by any means, but user like how it organizes their project-specific blade extensions into service container classes.
Let’s say, for example, that you have some custom directives around working with a shopping cart. Here’s a quick example of how it might look using Blade Extensions package:
<?php
namespace App\Blade;
use BitPress\BladeExtension\Contracts\BladeExtension;
class CartExtension implements BladeExtension
{
public function getDirectives()
{
return [
'cartcount' => [$this, 'getCartCount']
];
}
public function getConditionals()
{
return [
'cartempty' => [$this, 'isCartEmpty']
];
}
public function getCartCount()
{
// logic to return cart count
}
public function isCartEmpty()
{
// logic for empty cart
}
}
The above extension would provide the following directives in blade:
{{-- Conditional --}}
@cartempty
<p>The cart is empty</p>
@else
<p>The cart is not empty</p>
@endcartempty
{{-- Directive --}}
<span class="count">@cartcount</span>
It’s nothing special – it’s just PHP callables – but user like the feel of a dedicated class that can benefit from injecting services (i.e. a cart service) and keeping these related extensions grouped in one file.
If user need to add additional directives for the shopping cart, all they need to do is update the getDirectives()
method and define the associated callable.
You might find it interesting how this package’s service provider hooks into the Blade compiler. It’s pretty simple: the boot()
method just gets all services tagged with blade.extension
and registers the directives in the compiler.
// In the BladeExtensionServiceProvider::boot() method
foreach ($this->app->tagged('blade.extension') as $extension) {
if (! $extension instanceof BladeExtension) {
throw new InvalidBladeExtension($extension);
}
foreach ($extension->getDirectives() as $name => $callable) {
$this->app['blade.compiler']->directive($name, $callable);
}
foreach ($extension->getConditionals() as $name => $callable) {
$this->app['blade.compiler']->if($name, $callable);
}
}
The Blade Extensions package makes it easy to both create and register blade extensions in the service container:
php artisan make:blade Cart
And this is how you register it (it also tags the service) with the provided BladeRegistrar
class:
use App\Blade\CartExtension;
use BitPress\BladeExtension\Container\BladeRegistrar;
// ...
BladeRegistrar::register(CartExtension::class, function () {
return new CartExtension();
});
You can also use a provided helper method instead if you prefer:
blade_extension(CartExtension::class, function () {
return new CartExtension();
});
Essentially this is what the BladeRegistrar
does for you:
$this->app->singleton(CartExtension::class);
$this->app->tag(CartExtension::class, 'blade.extension');
Hire Laravel Developer from us, as we give you high quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft“.
To develop custom web app using Laravel, please visit our technology page.
Content Source:
- laravel-news.com
Laravel Homestead v6.6.0 Released – Latest Update
Homestead Introduction
Laravel strives to make the entire PHP development experience delightful, including your local development environment. Vagrant provides a simple, elegant way to manage and provision Virtual Machines.
Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!
Homestead runs on any Windows, Mac, or Linux system, and includes the Nginx web server, PHP 7.1, PHP 7.0, PHP 5.6, MySQL, PostgreSQL, Redis, Memcached, Node, and all of the other goodies you need to develop amazing Laravel applications.
Release v6.6.0
Laravel Homestead v6.6.0 was released over the weekend, most notably adding self-signed wildcard SSL certificates and Symfony 4 support.
To upgrade, you first need to update the Vagrant box:
vagrant box update
If you checked out Homestead, next you need to run:
git pull origin master
Or if you have Homestead installed in your project’s composer.json
file with "laravel/homestead"
: "^6"
and then run:
composer update
Here’s the list of important changes and additions in this release:
- PHP mongo driver updated from 1.2.9 to 1.3.3
- Restarted crond service once per provision.
- Refactored cron provisioning.
- Added symfony 4 support.
- Allowed Homestead.yaml to override default SSH port for Vagrant.
- Added support for the vagrant-hostmanager plugin.
- Allowed autonetwork plugin to be used.
Hire Laravel Developer from us, as we give you high quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft“.
To develop custom web app using Laravel, please visit our technology page.
Content Source:
- laravel.com
- laravel-news.com
What are the New Features in Laravel 5.5?
Version 5.5 of Laravel is officially released! This release is jam-packed with goodies and improvements, here’s a quick summarizing the highlight features.
1. New Route Methods introduced in Laravel 5.5
Laravel 5.5 shipped a couple of convenient shortcuts to the Laravel Router class that eliminates the need for creating a controller or closure only to return a simple view or redirect. If you missed them in the release notes, let’s look at them briefly, they are sure to simplify your code and remove a couple of files.
The Route::view method
The Route::view method eliminates the need for routes that only need a view returned. Instead of using a controller or a closure, you can define a URI and a path to a view file:
// resources/views/pages/about.blade.php
Route::view('/about', 'pages.about');
You can also pass in an array of variables that will be passed to the view:
Route::view('/about', 'pages.about', ['year' => date('Y')]);
The Route::redirect Method
The Route::redirect method also eliminates the need to create a controller or a closure only to return a redirect response:
Route::redirect('/old-about', '/about');
The third default argument, if not passed, is a 301 redirect. However, you can pass the third argument for a different status code. For example, if you want to create a 307 Temporary Redirect, it would look like this:
Route::redirect('/old-about', '/about', 307);
You can coordinate with hired a Laravel developer regarding develop and manage your website with latest laravel tools.
2. Laravel 5.5 Includes TrustedProxy
On a high level, Trusted Proxy tells Laravel about proxies that can be trusted and how to map X-Forwarded-* headers from the request.
Working with Proxies
It’s commonplace for us to need to work with cloud providers like Amazon Web Services and Content Delivery Networks (CDN) like Cloudflare for full site delivery, with the application sitting behind these services instead of being exposed directly to the world. Also, your application might even be behind a chain of proxies.
When your website or application has DNS pointed at CloudFlare, for example, the HTTP requests get proxied from CloudFlare to your application.
3. Dynamic templates in Laravel Blade with View::first
When building dynamic components or pages sometimes we want to display a custom template if it exists or otherwise fall back on a default one.
For example, imagine we are building a pages module, and some pages like “About Us” or “Contact Us” will need a custom template (for example to display pictures or a contact form), while others like “Terms of services” will do fine with a default template.
Using View::first
The view()->first() method allows us to replace the following code:
if (view()->exists('custom-template')) { return view('custom-template', $data); }
return view(‘default-template’, $data);
With a simpler, more expressive version:
return view()->first( ['custom-template', 'default-template'], $data );
You have to pass an array of templates as the first argument and the first method will load the first template it finds.
Of course, you can pass as many templates as you want and even use dynamic names:
return view()->first([ "pages/{$page->slug}", "pages/category-{$page->category->slug}", "pages/default-template" ], $data);
Remember you can also use this feature using its facade version:
\View::first($templates, $data)
This dynamic view loading feature was added to Blade in Laravel v5.5 and is a great way of keeping your controllers simple by avoiding extra conditionals when dealing with dynamic templates.
Hire Laravel Developer from us, as we give you high quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft“.
To develop the custom web app using Node.js, please visit our technology page.
Content Source:
- laravel-news.com