PHP & Web Development Blogs

Search Results For: help
Showing 1 to 5 of 17 blog articles.
434 views · 2 months ago

![Top 12 PHP Libraries to Leverage Your Web App Development](https://images.ctfassets.net/vzl5fkwyme3u/6Xd3PeEIm87bVI1UPb5q26/98abd4072971b7fc3f8d46aba3dc17f6/libraries2.png?w=1000)

PHP, by all means, is an immensely powerful language!

We may fall short of words, but there won't come any end to its qualities. The endless functionalities and possibilities of this server-side scripting language have managed to get it a strong and supportive community of PHP programmers on a global level. At present, PHP powers more than half on websites and applications on the internet.

**Do you know what makes PHP so praiseworthy?**

It is the simplicity, easy programming structure, and developer-friendly web functionalities that are to be credited to turn PHP into one of the top programming languages. You can create highly interactive and dynamic websites and applications with desired results by making use of PHP.

However, coding often could be a tough and tedious task to accomplish. As a solution to this, you get built-in PHP libraries that optimize the process of coding for maximum productivity.

### But what are these libraries?

That's exactly what you will find out as you move ahead in this article, a list of top 12 PHP libraries capable of leading the development process in an intended manner.

So, without waiting any further, let's move ahead to learn about PHP libraries in-depth.

#### [PChart](http://www.pchart.net/)

PChart is a PHP library assisting with the generation of text data in the form of something more appealing to the eyes and known as visual charts.

You can use this library to represent data as bar charts, pie charts, and many more different formats. The PHP script here utilizes SQL queries to put data in the impressive charts or graphs form.

#### [Mink](http://mink.behat.org/en/latest/)

Another well-known in the list of PHP libraries is Mink. It allows you to keep an eye on if a proper interaction is happening between your web apps and the browser. Eliminating the API differences between the two types of browser emulators, Mink offers an authentic testing environment for you. It also supports PHPUnit, Behat, and Symfony2.

#### [Monolog](https://github.com/Seldaek/monolog)

Monolog is a PHP logging library that helps you with saving logs to the specified locations by sending them to set files, sockets, inboxes, databases, or other web services. The use of the PSR-3 interface permits to type-hint logs in counter to your libraries that maintain optimum interoperability.

#### [Hoa](https://hoa-project.net/En/)

This modular, extensible, and structured set of PHP libraries we know as Hoa establishes a link between the research and the industry.

It recommends essential paradigms, mechanisms, and algorithms for building the reliability of a site. Many PHP developers in different parts of the world use Hoa for ideal PHP development.

#### [Guzzle](http://docs.guzzlephp.org/en/stable/)

Guzzle is an HTTP client library for PHP that enables you to send HTTP requests to combine with web services.

It offers a simple interface that makes the development of query strings, POST requests, HTTP cookies, and many other attributes possible. You can also use Guzzle to send synchronous and asynchronous requests from the similar interface.

#### [Ratchet](http://socketo.me/)

If your need is to develop real-time, two-directional apps between clients and servers over WebSockets, Ratchet is the PHP library you need to do it effectively.

Creating event-driven apps with Ratchet is a rapid, simple, and easy job to do!

#### [Geocoder](https://geocoder-php.org/)

Geocoder is a library to create applications that are very well geo-aware.

With Geocoder, there is an abstraction layer that helps with geocoding manipulations.

It is further split into two parts, known as HttpAdapter and Provider.

#### [ImageWorkshop](https://phpimageworkshop.com/)

ImageWorkshop is an open-source PHP library letting you work over the manipulation of images with layers. You can crop, resize, add watermarks, create thumbnails, and so much more. You can also enhance the images on the sites.

#### [PhpThumb](http://phpthumb.sourceforge.net/)

phpThumb is the library specialized at handling the work associated with creating thumbnails with minimal coding. Accepting every image source type and image formats, it makes you do a lot ranging from rotating or cropping to watermarking or defining the image quality.

#### [Parody](https://github.com/dotink/Parody)

This simple library we know as Parody is used to copy classes and objects. It also provides results for method calls, acquiring properties, instantiating objects, and more. Sequential method chaining is used by Parody to produce defining class structures.

#### [Imagine](https://imagine.readthedocs.io/en/stable/)

This object-oriented PHP library is meant for working with images along with manipulating them. The often adopted operations such as resizing, cropping, and applying filters happen instantly and relatively well with Imagine.

With Imagine, you get a color class that forms the RGB values of any given color. Draw shapes like arc, ellipse, line, etc. with the features available.

#### [PhpFastCache](https://www.phpfastcache.com/)

PhpFastCache is an open-source library that makes caching feasible. Coming as a single-file, it can be integrated within a matter of minutes.

Caching methods supported by PhpFastCache involve apc, memcache, memcached, wincache, pdo, and mpdo.

**The Bottom Line**

It's not about what extra difference these libraries make; it's about what significant individual contributions these libraries make for a final desired PHP app or website.

A [PHP programmer](https:/ /hireindependentdevelopers.com/php-developers/), too, agrees with these libraries' benefits.

It's your time now to try and believe!

466 views · 2 months ago

![](https:/ /cdn.filestackcontent.com/vQJAo2oUSGivid9AqVtT)

People that visit your website face an invisible threat each time they log on. Small businesses are especially vulnerable to digital data breaches, and that can change the way your customers feel about you. But, although you cannot stop hackers from trying, there are things you can do as a business owner to make your website a safer experience for everyone. Keep reading for tips.

### Mature digitally.

You may be ahead of the times when it comes to products and services, but, chances are, your website hasn't fully kept up. It's time to learn all you can about the internet and digital security. If you are already somewhat tech savvy, a [PHP Security Course](https:/ /nomadphp.com/courses/php-security) from Nomad PHP can help you better understand everything from cryptography to website error messages.

Adapting to today's digital environment means transforming your website to quickly and easily identify threats via machine learning and network monitoring. And, as Upwork explains, digital [maturity](https:/ /www.upwork.com/resources/accelerating-your-digital-transformation-in-2020) not only keeps your website safe, but adopting this mindset can also increase your efficiency and accuracy by reducing human errors.

### Understand the threats.

It is not enough to simply keep up with your website, you also have to understand the types of threats that are out there. You're likely familiar with ransomware and phishing, but, it's also a good idea to know how a website can get hacked. Your site's content management system and vulnerabilities within your operating system are all [weak points](https:/ /www.weborion.io/blog/five-ways-a-website-can-be-hacked/) that hackers can easily identify.

### Insist on security measures.

When customers log into your website, they input their credentials. Each time they do so, you can best protect their information by keeping your systems up to date. You'll also want to ensure that your site is hosted on a secure service and that you have an [SSL certificate](https:/ /us.norton.com/internetsecurity-how-to-ssl-certificates-what-consumers-need-to-know.html) installed.

If you are not already, have your IT department or managed IT services perform regular website security checks. PhoenixNAP, an IT services provider, notes that those websites working via WordPress should also be safely outfitted with the most recent [security plug-ins](https:/ /phoenixnap.com/blog/how-to-secure-a-website).

### Eliminate spam.

If your website allows for comments that are not manually approved, anyone on the internet can post. This leaves it open for hackers and other unscrupulous individuals to [comment with spam](https:/ /www.shivarweb.com/2450/my-blog-comment-spam-is-too-high-heres-why/) and malicious links that your customers may inadvertently click on. While many of these simply exist as a way for the commenter to [drive traffic](https:/ /www.wordstream.com/blog/ws/2014/08/14/increase-traffic-to-my-website) to another website, others are designed to draw your readers' attention, gain their trust, and access their personal information.

### Prioritize passwords.

Your customers' passwords are the keys by which they open the door to your website. Unfortunately, many people do not treat them with as much care as they do the keys they use in the non-digital world.

It's true, passwords can be a pain, but you are not doing yourself or your customers any favors by allowing simple one-word passcodes to access your site. Instead, design your site to require a strong password. How-To Geek asserts that this will have a [minimum of 12 characters](https:/ /www.howtogeek.com/195430/how-to-create-a-strong-password-and-remember-it/) and include a combination of upper and lower case letters, symbols, and numbers.

While you will likely rely on your IT experts to secure your website, the truth is that it is ultimately up to you to ensure this is done. So even if you are not a digital mastermind, knowing all you can about web security can help you be a better business owner. Your customers will be safer, and a secure website is just one way to strengthen your business's online presence and keep up with today's -- and tomorrow's -- technology.

548 views · 3 months ago

![Using AI for Weather Forecasting](https:/ /cdn.filestackcontent.com/NZd1Hj1pTvmhJqRqIYcw)

> Technology is constantly changing the way we interact, research, and react. One such way artificial intelligence is impacting our daily lives, and we may not even realize it is in weather forecasting.

The forecast we usually have been receiving in our phones and in older times primarily in newspapers, was based on data collected via satellites, radar system and weather balloons. In recent times there has been the addition of IoT based sensors as well. However, with the advent of Artificial Intelligence (AI) finding its way in numerous areas, AI has taken a role in improving the accuracy of weather as well.

### The Dataset expansion

A significantly enormous set of data is available - from the weather satellites in space, to the private and government owned weather stations which are gaining real-time data. IBM for instance has more the 0.25 million weather stations that help IBM collect real-time data. Additionally, as we are in the age of Internet of Things (IOT), each small device to big device- cellphones, solar panels and vehicles everything has become or is yet to become yet another data source. Companies like GE have installed IOT street lights, which help in monitoring air quality and humidity. These are some of the few sources which help us in collecting the vast amount of data necessary for building on the AI technology, in future these sources and the amount of available data would grow exponentially.

### Google and Weather forecast

Using the AI technology Google is able to develop a weather forecast tool, it has been trained to predict rainfalls accurately as much as six hours before. The underlying technology on which this prediction is build upon is U-Net convolutional neural network which is originally used in biomedical research. It works by taking satellite images as input and uses AI technology to transform these images into high resolution images. The only off-set is this is not real-time prediction and the delay due to complex calculations results in using six-hour old data and hence can only predict six-hours before.

### IBM and its efforts in weather prediction

The quest for IBM to venture into weather forecasting began with IBM acquiring The Weather Company. IBM plans on using the large amount of weather data available coupled with IBM Watson and the cloud platform to enhance weather forecasting. In 2019 IBM developed Global High-Resolution Atmospheric Forecasting System (GRAF) in order to forecast weather conditions 12 hours prior to a greater degree of accuracy. The radius encompassed by the GRAF is also more narrowed down up to 3 kilometers as opposed to generally being 10-15 kilometers. Another of its marvel is that it gives accurate predictions down to each hour and not just daily.

### Artificial Intelligence and Panasonic

Panasonic is the company behind TAMDAR, the weather sensor installed on commercial airplanes. With this advantage of extensive amount of data from in-flight sensors as well as publicly available data Panasonic developed Global 4D Weather. Proving to their claim of being the most advanced global forecasting platform globally they were able to timely predict Hurricane Irma in its early days.

## Uses of Weather Forecasting

### Sales

Everyday life decisions are affected by weather, it makes us choose in the way we travel, things we eat and things we buy to wear. The rise in temperature may increase sales of chilled drinks, if the company is fully aware of the forecast it would be able to manage productions as per demand. AI can help brands in maximizing sales based on weather forecasts and in minimizing waste.

### Natural Disasters

The Panasonic Global 4D weather predicting Hurricane Irma is just another example where timely prediction can save millions of lives in face of situations like floods and Hurricanes. Companies like IBM combine weather forecasting data with utilities distribution network, which enables them to narrow down areas with likely outages. This enables utilities to place their workforce timely so the repair process catering to damage repairs post disasters is shortened. This in turn brings huge benefits to the overall economy.

### Agriculture

The weather and agriculture have the most obvious correlation, each process in farming from sowing to reaping all depends on the weather. As farmers cultivate on huge farming lands, accurate information about each part of the land can help farmers in improving their crops and yield by manifolds. Weather conditions can lead to almost 90 percent of crop losses, 25 percent of these losses can be avoided using accurate AI prediction models to forecast weather and in turn improve the yield.

### Transportation

Sea travel has always been eventful, timely prediction of storms by using machine learning techniques and hyper-local data allows companies to plan shipments accordingly and avoid severe weather conditions that usually result in delays. Tools like IBM’s Operations Dashboard for Ground Transportation equips in enhancing productivity based on weather predictions.

Another of the implementation of AI in transportation industry corelating to weather is fuel consumption. For instance, using weather prediction models to reduce airplane fuel consumption during its ascent.

To conclude Artificial Intelligence has a key role to play in weather forecasting, weather direct or indirectly impacts each sector in the economy. As the amount of information available to improve predictions increases exponentially it gives a chance to AI to improve accuracy even further. As we continue narrowing down weather conditions precise to time and location the benefits of such advancements across all industries are innumerable.

2546 views · 5 months ago

![Ideas to help your PHP dev team grow their skills](https:/ /cdn.filestackcontent.com/LcqSW9KZSZarYYZWaQVH)

> Your biggest asset is also your biggest risk... your developers

Your business thrives because of the incredible work and innovation of your developers. With simple keystrokes your developers can completely transform your business, add new features, and drive new sales.

But those same keystrokes can take down production, create security back doors, and put your business at risk. That's why it's more important than ever for your team members to be up to speed with the latest technology, especially around performance and security.

Of course, some things are easier said than done - after all everyone is super busy these days. So how can you help keep your team members learning, and putting your business first in the process?

## Conference Parties

There's nothing better than attending a [PHP or programming conference](https:/ /www.php.net/conferences/) in person - the chance to meet speakers face to face, to network, the knowledge, and the hallway track. However, many companies aren't able to afford multiple (or even one) conference for their developers - especially ones that require airfare and hotel.

However, that doesn't mean you shouldn't still participate in these conferences. The good news is that roughly once a quarter [Nomad PHP](/live) streams talks from a conference right to your computer. This means that your team members can all participate in a multi-day conference from the comfort of your office (or their home) - and you can provide this for your team for [less than the cost](/teams) of a single conference ticket!

Make the conference party even more special by providing lunch during the lunch break, bringing in party gifts, having give-aways during the conference, and planning activities during longer breaks for your team.

Since many conferences take place on Friday, not only are you providing invaluable training and an incredible work benefit, but ending the week on a super positive note that your team members will appreciate (and your risk assessment teams will greatly appreciate as new security practices and compliance practices are put into place).

## Monthly Lunch and Learns

Every month Nomad PHP offers [live virtual talks](/live) by the industry's top experts. With talks at 11am Pacific, and 6pm Pacific it's a perfect time to grab a conference room and order a couple pizzas for lunch (or if Eastern, grab some snacks and maybe a beer) and play the monthly meeting on the large screen.

Your team members will have the opportunity to take notes, discuss with each other, and perhaps most importantly ask the speaker real-world questions that directly impact your business, providing tangible solutions to the problems they are facing.

And since every Nomad PHP Pro meeting [is recorded](/videos), your team members can refer back to the video at any time, watching sections relevant to them or digging in for more information.

## Developer Book Club

Encourage your team members to share what they're learning with others, and help build each other up. Not only are you helping grow skills and ensure your team is following the latest best practices, but you're also fostering a mentor-mentality within your team - where each team member feels invested in the growth of other members.

With Nomad PHP you receive a new issue of [php[architect]](/books) each month and have several [additional books](/books) available to read on demand - providing the latest updates and an invaluable resource to help your book club get started.

## Developer Movie Nights

Sometimes we all just want to get away, grab some popcorn, and watch a movie. Similar to lunch and learns, give your developers a night or two where they can get together and watch one of the [250+ training videos](/videos) available on Nomad PHP. You can even make it a movie marathon!

Whether it's pizza, popcorn, sodas, beers - your team members will have the chance to kick back, relax a bit, build team camaraderie, and learn valuable skills to help your business succeed. Essentially, turning a training day into a fun team-bonding activity.

## Learning Path Challenges

Every company has challenges, and areas they need their team members to master. Whether it's [DevOps](/videos/devops) and [containerization](/videos/containerization), [security](/videos/security), [performance](/videos/performance), [management](/search/videos/soft-skills?search_query=manage), [modernization](/videos/upgrading), or [soft skills](/videos/soft-skills) - work with your team to determine what skills will help them succeed and work with your team members to put together video learning paths.

Your team members can watch through these [videos on-demand](/videos), go back and replay to refresh their knowledge, and work their way towards mastery in the subjects that will help your company succeed.

## Certification

Show that you are invested in your developers by helping them earn [Professional Certification](/certification). These certifications demonstrate that your team members have a fundamental grasp of the technology they are working with and understand when and how to use this technology.

With [free certification exams](/certification) included with Nomad PHP - you no longer have to worry about failed exams or expensive test credits. Your team members can take the exams at their own pace, discover the areas they need to improve, and take the exam again when they are ready. After all, shouldn't the goal of certification be to help your developers learn these skills and prove their expertise?

You can go even further with certifications by having a special [company award](https:/ /amzn.to/359HSLd), [framing their certificate](https:/ /amzn.to/2SnEOpV), or calling out newly certified developers at team meetings or all-hands.

## Learning Incentives/ Rewards

Of course there are even more ways you can help your developers learn new skills, grow their careers, and build loyalty within your company. With Nomad PHP there are numerous ways for your team members to grow their skills, and numerous ways you can reward/ incentivize them - from rewards for the most active learner, to setting goals for learning new skills, to obtaining certifications, to attending streams, to watching videos on-demand. All of these are included with our [Professional Nomad PHP Team subscriptions](/teams).

### Want to learn more about getting a Nomad Team Subscription for your developers? Give us a call (844) CODE-PHP

**Have more ideas on how to help your developers grow their skills or help employers make education more accessible? Please leave your ideas in the comments below!**

1415 views · 6 months ago

![Laravel Eloquent Relationship Part 2](https:/ /images.ctfassets.net/vzl5fkwyme3u/3gY1sugUC3gTUtfgbhgNi5/410818aed6a8d4ea08e0ec796477291c/laravel_blog.png?w=1000)

As you all know, Laravel Eloquent Relationships are powerful and easy methods introduced by Laravel for helping developers to reduce the complexity when connecting with multiple tables. While connecting with multiple tables, this method is very easy for developers for creating the application

Here you can see the next three methods of the eloquent relationships:

1. Has Many Through Relationship

2. One to Many Polymorphic

3. Many to many Polymorphic

## HAS MANY THROUGH ELOQUENT RELATIONSHIP

Has many through is a little bit complicated while understanding. I will provide a shortcut method to provide access data of another mode relationship. We will create a user table, post table, and country table and they will be interconnected with each other.

Here we will see Many through relationship will use `hasManyThrough()` for the relation

### Create Migrations

**Users table**

```

Schema::create('users', function (Blueprint $table) {

$table->increments('id');

$table->string('name');

$table->string('email')->unique();

$table->string('password');

$table->integer('country_id')->unsigned();

$table->rememberToken();

$table->timestamps();

$table->foreign('country_id')->references('id')->on('countries')

->onDelete('cascade');

});

```

**Posts table**

```

Schema::create('posts', function (Blueprint $table) {

$table->increments('id');

$table->string("name");

$table->integer('user_id')->unsigned();

$table->timestamps();

$table->foreign('user_id')->references('id')->on('users')

->onDelete('cascade');

});

```

**Countries table**

```

Schema::create('countries', function (Blueprint $table) {

$table->increments('id');

$table->string('name');

$table->timestamps();

});

```

### Create Models

**Country Model**

```

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Country extends Model

{

public function posts(){

return $this->hasManyThrough(

Post::class,

User::class,

'country_id', / / Foreign key on users table...

'user_id', / / Foreign key on posts table...

'id', / / Local key on countries table...

'id' / / Local key on users table...

);

}

}

```

**Now we can retrieve records by**

```

$country = Country::find(1);

dd($country->posts);

```

## ONE TO MANY POLYMORPHIC RELATIONSHIP

One to many polymorphic relationships used one model belongs to another model on a single file. For example, we will have tweets and blogs, both having the comment system. So we need to add the comments. Then we can manage both in a single table

Here we will use sync with a pivot table, create records, get all data, delete, update, and everything related to one too many relationships.

Now I will show one too many polymorphic will use `morphMany()` and `morphTo()` for relation.

### Create Migrations

**Posts table**

```

Schema::create('posts', function (Blueprint $table) {

$table->increments('id');

$table->string("name");

$table->timestamps();

});

```

**Videos Table**

```

Schema::create('videos', function (Blueprint $table) {

$table->increments('id');

$table->string("name");

$table->timestamps();

});

```

**Comments Table**

```

Schema::create('comments', function (Blueprint $table) {

$table->increments('id');

$table->string("body");

$table->integer('commentable_id');

$table->string("commentable_type");

$table->timestamps();

});

```

## Create Models

**Post Model**

```

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model

{

/ **

* Get all of the post's comments.

*/

public function comments(){

return $this->morphMany(Comment::class, 'commentable');

}

}

```

**Video Model**

```

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Video extends Model{

/ **

* Get all of the post's comments.

*/

public function comments(){

return $this->morphMany(Comment::class, 'commentable');

}

}

```

**Comment Model**

```

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model{

/ **

* Get all of the owning commentable models.

*/

public function commentable(){

return $this->morphTo();

}

}

```

### Create Records

```

$post = Post::find(1);

$comment = new Comment;

$comment->body = "Hi Harikrishnan";

$post->comments()->save($comment);

/ / Video

$video = Video::find(1);

$comment = new Comment;

$comment->body = "Hi Harikrishnan";

$video->comments()->save($comment);

```

Now we can retrieve records

```

$post = Post::find(1);

dd($post->comments);

$video = Video::find(1);

dd($video->comments);

```

## MANY TO MANY POLYMORPHIC RELATIONSHIPS

Many to many polymorphic is also a little bit complicated like above. If we have a tweet, video and tag table, we need to connect each table like every tweet and video will have multiple persons to tag. And for each and every tag there will be multiple tweet or videos.

Here we can understand the creating of many to many polymorphic relationships, with a foreign key schema of one to many relationships, use sync with a pivot table, create records, attach records, get all records, delete, update, where condition and etc..

Here `morphToMany()` and `morphedByMany()` will be used for many to many polymorphic relationships

### Creating Migrations

**Posts Table**

```

Schema::create('posts', function (Blueprint $table) {

$table->increments('id');

$table->string("name");

$table->timestamps();

});

```

**Videos Table**

```

Schema::create('videos', function (Blueprint $table) {

$table->increments('id');

$table->string("name");

$table->timestamps();

});

```

**Tags table**

```

Schema::create('tags', function (Blueprint $table) {

$table->increments('id');

$table->string("name");

$table->timestamps();

});

```

**Taggables table**

```

Schema::create('taggables', function (Blueprint $table) {

$table->integer("tag_id");

$table->integer("taggable_id");

$table->string("taggable_type");

});

```

### Creating Models

**Post Model**

```

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model

{

/ **

* Get all of the tags for the post.

*/

public function tags(){

return $this->morphToMany(Tag::class, 'taggable');

}

}

```

**Video Model**

```

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Video extends Model

{

/ **

* Get all of the tags for the post.

*/

public function tags(){

return $this->morphToMany(Tag::class, 'taggable');

}

}

```

**Tag Model**

```

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Tag extends Model

{

/ **

* Get all of the posts that are assigned this tag.

*/

public function posts(){

return $this->morphedByMany(Post::class, 'taggable');

}

/ **

* Get all of the videos that are assigned this tag.

*/

public function videos(){

return $this->morphedByMany(Video::class, 'taggable');

}

}

```

**Creating Records**

```

$post = Post::find(1);

$tag = new Tag;

$tag->name = "Hi Harikrishnan";

$post->tags()->save($tag);

$video = Video::find(1);

$tag = new Tag;

$tag->name = "Vishnu";

$video->tags()->save($tag);

$post = Post::find(1);

$tag1 = new Tag;

$tag1->name = "Kerala Blasters";

$tag2 = new Tag;

$tag2->name = "Manajapadda";

$post->tags()->saveMany([$tag1, $tag2]);

$video = Video::find(1);

$tag1 = new Tag;

$tag1->name = "Kerala Blasters";

$tag2 = new Tag;

$tag2->name = "Manajappada";

$video->tags()->saveMany([$tag1, $tag2]);

$post = Post::find(1);

$tag1 = Tag::find(3);

$tag2 = Tag::find(4);

$post->tags()->attach([$tag1->id, $tag2->id]);

$video = Video::find(1);

$tag1 = Tag::find(3);

$tag2 = Tag::find(4);

$video->tags()->attach([$tag1->id, $tag2->id]);

$post = Post::find(1);

$tag1 = Tag::find(3);

$tag2 = Tag::find(4);

$post->tags()->sync([$tag1->id, $tag2->id]);

$video = Video::find(1);

$tag1 = Tag::find(3);

$tag2 = Tag::find(4);

$video->tags()->sync([$tag1->id, $tag2->id]);

```

Now we can retrieve records

```

$post = Post::find(1);

dd($post->tags);

$video = Video::find(1);

dd($video->tags)

$tag = Tag::find(1);

dd($tag->posts);

$tag = Tag::find(1);

dd($tag->videos);

```

Hence we completed all the relationships. In the above blog how has many through relationship, one to many polymorphic relationships and many to many polymorphic are working. This feature is introduced from Laravel 5.0 onwards and till the current version. Without the model, we can’t able to do this relationship. If we are using an eloquent relationship it will be very useful while developing an application.

SPONSORS

Faster PHP Cloud Hosting