Categories
Programming Technology Web Development

Pagination in laravel relation

public function get_shop_products($shop_id)
{
$shop = Shop::query()
->where(‘id’ , $shop_id)
->first();
$shop->setRelation(‘products’ , $shop->products()->paginate(10));
return new ShopProductsResource($shop);
}

Masoud Hosseini

Categories
Programming Technology Useful Addresses Web Development

I love Frappe Framework

In this post, I want to write about a miracle in the software development world.

Imagine you can create your database entities with some clicks; you have many types of fields that are built in that software.

For a programmer who codes in pure PHP or python with a front-end framework, it takes more than 1 month to create a blog and shop website, but you can have all of that in one or two days with Frappe; Wow 🙂 What amazing!

You can read more about it on its official website: frappeframework.com

I also created a GitHub repository to keep some sample script codes that during working with frappe you probably need to use.

You can have it here (don’t forget to give it a start and communicate):

https://github.com/masoud-me/frappe-sample-scripts

Categories
Best practice devops Programming Technology Web Development

Implement Rest APIs more efficient

Most web applications are implemented based on Rest Full APIs and as I researched huge part of them are not implemented based on best practices and clean code principles, so I decided to collect some points in a couple of posts to help make them more efficient APIs and Applications.

Let’s Look at other kinds of APIs

you can easily research and find out more about all of these kine of API design methodologies but here I’m going to just collect best part of them to create a document to implement Rest API in best practice.

Graphql

the best part of graphql is that you can design your API for the front end to just get whatever need, not more.

it can bring us better speed because less amount of packets is transferring over the network.

gRPC

Socket

Categories
Web Development

What is Graphql

I worked many years with Rest API, and because of a special situation, I had to work with Garphql in my projects.

After working with Graphql, I shared my experience and some valuable tips here.

  • what is Graphql?
  • where need to use Graphql?
  • Graphql or Rest ?

What is Graphql?

It was always a problem in projects to communicate between back-end and front-end using Rest APIs.

By using Rest API, you need to create an endpoint for every request or format data that the frontend needs.

But, by using Graphql, you prepare an endpoint, and the frontend will get the data with every format it wants.

After this explanation, like as other resources, we can say that: Graphql is a query language for the frontend which backend is organized.

Categories
Programming Technology Web Development

Using Types in PHP is one of the least used features

Using Types in PHP is one of the least used features, but very powerful features available in PHP. This is a feature that can save you and other developers a whole lot of stress (if you work with a team).

Of course, you can write function descriptions, but it becomes quite a daunting task to write function descriptions for all your functions and variables in a large project.

When someone else wants to use your function or even you want to use it after a couple of weeks later, it needs to check the function’s body to recognize which types you should pass to the function while using, if you don’t specify arguments types.

Ex:

function getItem(array $item) {
return allItems()[$item[0]];
}

This will make sure that whatever is passed in here is the type needed. You can read more from www.php.net

For more tips:
https://lnkd.in/eWgvUVKS