mirror of
https://github.com/archtechx/laravel-tips.git
synced 2025-12-12 13:24:03 +00:00
959 lines
73 KiB
HTML
959 lines
73 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
<title>Laravel</title>
|
|
<link rel="stylesheet" href="/css/app.css?id=d5acc62a4ce7a6842556">
|
|
<script type="module" src="/js/app.js?id=a136d2a5a73d65f4c129"></script>
|
|
<link href="https://fonts.rcvd.io/iA%20Writer/stylesheet.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
<body class="antialiased bg-white">
|
|
<div class="w-full p-3 text-center min-h-screen flex justify-between flex-col">
|
|
<header class="mt-8">
|
|
<h1 class="text-5xl w-full">Laravel Code Tips</h1>
|
|
<h2 class="mt-6 text-2xl text-gray-700">Make your Laravel code cleaner, faster, and safer.</h2>
|
|
<div class="mt-6 text-gray-800 text-lg">
|
|
<a class="inline" href="https://twitter.com/LaravelCodeTips" target="_blank">
|
|
<span class="link">Twitter</span>
|
|
</a>
|
|
<span class="px-1">·</span>
|
|
<a class="inline" href="https://newsletter.laravel-code.tips" target="_blank">
|
|
<span class="link">Newsletter</span>
|
|
</a>
|
|
<span class="px-1">·</span>
|
|
<a class="inline" href="https://t.me/laraveltips" target="_blank">
|
|
<span class="link">Telegram</span>
|
|
</a>
|
|
</div>
|
|
</header>
|
|
<main class="mx-auto flex justify-between items-center gap-8 w-1/2">
|
|
<section role="feed" class="my-8">
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/use-strict-comparison'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/use-strict-comparison">🔥 Use strict comparison</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Use strict comparison" src="https://pbs.twimg.com/media/Ean722QXgAENwmW.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>ALWAYS use strict comparison (=== and !==). If needed, cast things go the correct type before comparing. Better than weird == results</p>
|
|
<p>Also consider enabling strict types in your code. This will prevent passing variables of wrong data types to functions <a href="https://t.co/C0is2rghbs">https://t.co/C0is2rghbs</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/if-you-want-to-identify-teams-workspaces-etc-by-path-you-dont-have-to-pass-the-team-id-to-every-route'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/if-you-want-to-identify-teams-workspaces-etc-by-path-you-dont-have-to-pass-the-team-id-to-every-route">🔥 If you want to identify teams, workspaces, etc by path, you don't have to pass the team ID to every route</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="If you want to identify teams, workspaces, etc by path, you don't have to pass the team ID to every route" src="https://pbs.twimg.com/media/EidKFFnX0AEEjwr.png?name=small">
|
|
<img alt="If you want to identify teams, workspaces, etc by path, you don't have to pass the team ID to every route" src="https://pbs.twimg.com/media/EidKYlkWoAAWkLD.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>In the example below, the value reaches the middleware, where you can do some stuff, and then is REMOVED from the route parameters before being passed to the action. <a href="https://t.co/3TNUnucmz3">https://t.co/3TNUnucmz3</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/example-checking-a-parent-relationship-for-some-things'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/example-checking-a-parent-relationship-for-some-things">🔥 Example: Checking a parent relationship for some things</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Example: Checking a parent relationship for some things" src="https://pbs.twimg.com/media/EidbX_UWAAMeB6-.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Such as, checking if an Order is locked inside an OrderProduct.</p>
|
|
<p>OrderProducts cannot be added to/changed in a locked order. <a href="https://t.co/4v8iIkebPk">https://t.co/4v8iIkebPk</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/create-model-methods-for-business-logic'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/create-model-methods-for-business-logic">🔥 Create model methods for business logic</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Create model methods for business logic" src="https://pbs.twimg.com/media/Ean0WGiWAAAg4cu.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Your controllers should be simple. They should say things like "create invoice for order". They shouldn't be concerned with the details of how your database is structured.</p>
|
|
<p>Leave that to the model. <a href="https://t.co/1w1s2sbwkO">https://t.co/1w1s2sbwkO</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/yesterday-in-my-at-laracononline-talk-i-explained-how-to-use-the-query-builder-when-method-to-handle-complex-sorting'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/yesterday-in-my-at-laracononline-talk-i-explained-how-to-use-the-query-builder-when-method-to-handle-complex-sorting">🔥 Yesterday in my @LaraconOnline talk I explained how to use the query builder when() method to handle complex sorting</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Yesterday in my @LaraconOnline talk I explained how to use the query builder when() method to handle complex sorting" src="https://pbs.twimg.com/media/ERyNRSIX0AEjjWo.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>What you may not realize is that the when() method also accepts a second callback for the falsy case. This is really helpful for setting a sort default. 🤩 <a href="https://t.co/11eni5DW1Z">https://t.co/11eni5DW1Z</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/its-about-the-micro'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/its-about-the-micro">🔥 It's about the *micro*</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Using some "macro" philosophy for structuring your code, like hexagonal architecture or DDD won't save you.</p>
|
|
<p>A clean codebase is the result of constant good decisions at the micro level.</p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/dont-use-a-controller-namespace'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/dont-use-a-controller-namespace">🔥 Don't use a controller namespace</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Don't use a controller namespace" src="https://pbs.twimg.com/media/Ean6NFJX0AAfiXT.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Instead of writing controller actions like PostController@index, use the callable array syntax [PostController::class, 'index'].</p>
|
|
<p>You will be able to navigate to the class by clicking PostController. <a href="https://t.co/h2UF1te3E3">https://t.co/h2UF1te3E3</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/use-data-transfer-objects-dtos'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/use-data-transfer-objects-dtos">🔥 Use Data Transfer Objects (DTOs)</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Use Data Transfer Objects (DTOs)" src="https://pbs.twimg.com/media/Ean3uMaWAAApBhb.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Rather than passing a huge amount of arguments in a specific order, consider creating an object with properties to store this data.</p>
|
|
<p>Bonus points if you can find that some behavior can be moved into to this object. <a href="https://t.co/C1FSrjYWLP">https://t.co/C1FSrjYWLP</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/use-expressive-names-for-methods'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/use-expressive-names-for-methods">🔥 Use expressive names for methods</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Use expressive names for methods" src="https://pbs.twimg.com/media/Ean4xcqWAAUsjdG.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Rather than thinking "what can this object do", think about "what can be done with this object". Exceptions apply, such as with action classes, but this is a good rule of thumb.</p>
|
|
<p><a href="https://t.co/LScInA8ToE">https://t.co/LScInA8ToE</a> <a href="https://t.co/lLm5SaWk2m">https://t.co/lLm5SaWk2m</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/theres-great-value-in-understanding-how-object-state-of-models-works-this-is-mostly-relevant-in-feature-tests-because-they-touch-many-parts-of-your-codebase-in-one-phplaravel-app-state'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/theres-great-value-in-understanding-how-object-state-of-models-works-this-is-mostly-relevant-in-feature-tests-because-they-touch-many-parts-of-your-codebase-in-one-phplaravel-app-state">🔥 There's great value in understanding how object state of Models works. This is mostly relevant in (Feature) tests because they touch many parts of your codebase in one PHP/Laravel App state</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="There's great value in understanding how object state of Models works. This is mostly relevant in (Feature) tests because they touch many parts of your codebase in one PHP/Laravel App state" src="https://pbs.twimg.com/media/Eic9xP2XsAoo8ay.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>For example, use $model->is($anotherModel) to check if they refer to the same row. <a href="https://t.co/kBquNQYPgA">https://t.co/kBquNQYPgA</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/consider-using-helpers-instead-of-facades-they-can-clean-things-up'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/consider-using-helpers-instead-of-facades-they-can-clean-things-up">🔥 Consider using helpers instead of facades. They can clean things up</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Consider using helpers instead of facades. They can clean things up" src="https://pbs.twimg.com/media/Ean7QGBXYAEt_l2.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>This is largely a matter of personal preference, but calling a global function instead of having to import a class and statically call a method feels nicer to me.</p>
|
|
<p>Bonus points for session('key') syntax. <a href="https://t.co/AbMzJl4Puz">https://t.co/AbMzJl4Puz</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/closure-validation-rules-are-theyre-often-better-than-creating-a-class-just-for-a-single-use'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/closure-validation-rules-are-theyre-often-better-than-creating-a-class-just-for-a-single-use">🔥 Closure validation rules are 🔥. They're often better than creating a class just for a single use</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Closure validation rules are 🔥. They're often better than creating a class just for a single use" src="https://pbs.twimg.com/media/EidAtSYXgAc-6tH.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Create a class if it's used on multiple places or way too complex. <a href="https://t.co/nslCQb8pDh">https://t.co/nslCQb8pDh</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/use-events'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/use-events">🔥 Use events</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Use events" src="https://pbs.twimg.com/media/Ean07-jXkAErgaL.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Consider offloading some logic from controllers to events. For example, when creating models.</p>
|
|
<p>The benefit is that creating these models will work the same everywhere (controllers, jobs, ...) and the controller has one less worry about the details of the DB schema <a href="https://t.co/6zJaMPScBk">https://t.co/6zJaMPScBk</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/create-single-use-blade-includes'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/create-single-use-blade-includes">🔥 Create single-use Blade includes</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Similar to single-use traits.</p>
|
|
<p>This tactic is great when you have a very long template and you want to make it more manageable.</p>
|
|
<p>There's nothing wrong with @including headers and footers in layouts, or things like complex forms in page views.</p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/you-can-return-mailables-as-responses-from-controllers-it-will-show-the-rendered-version-in-the-browser'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/you-can-return-mailables-as-responses-from-controllers-it-will-show-the-rendered-version-in-the-browser">🔥 You can return Mailables as responses from controllers. It will show the rendered version in the browser</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="You can return Mailables as responses from controllers. It will show the rendered version in the browser" src="https://pbs.twimg.com/media/Eic6iydX0AgLupY.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Great for debugging/tweaking the design. <a href="https://t.co/bdB22XLnHz">https://t.co/bdB22XLnHz</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/create-fluent-objects'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/create-fluent-objects">🔥 Create fluent objects</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Create fluent objects" src="https://pbs.twimg.com/media/Ean3zqXWAAASnOP.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>You can also create objects with fluent APIs. Gradually add data by with separate calls, and only require the absolute minimum in the constructor.</p>
|
|
<p>Each method will return $this, so you can stop at any call. <a href="https://t.co/826OBHPEAX">https://t.co/826OBHPEAX</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/consider-using-form-requests'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/consider-using-form-requests">🔥 Consider using form requests</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Consider using form requests" src="https://pbs.twimg.com/media/Ean0kWgXgAAcOXm.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>They're a great place to hide complex validation logic.</p>
|
|
<p>But beware of exactly that — hiding things. When your validation logic is simple, there's nothing wrong with doing it in the controller. Moving it to a form request makes it less explicit <a href="https://t.co/RwzDxANxXj">https://t.co/RwzDxANxXj</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/wanna-update-a-set-of-eloquent-models-and-have-the-change-updated-in-the-database-and-in-your-in-memory-instances-but-dont-wanna-incur-a-database-query-for-each-model'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/wanna-update-a-set-of-eloquent-models-and-have-the-change-updated-in-the-database-and-in-your-in-memory-instances-but-dont-wanna-incur-a-database-query-for-each-model">🔥 Wanna update a set of Eloquent models and have the change updated in the database and in your in-memory instances, but don't wanna incur a database query for *each* model?</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Wanna update a set of Eloquent models and have the change updated in the database and in your in-memory instances, but don't wanna incur a database query for *each* model?" src="https://pbs.twimg.com/media/EWVoC3jVcAEg0JX.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Custom collections got you sorted. Love these methods. <a href="https://t.co/1sehVNNDug">https://t.co/1sehVNNDug</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/instead-of-writing-repetitive-else-if-statements-use-an-array-to-look-up-the-wanted-value-based-on-the-key-you-have'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/instead-of-writing-repetitive-else-if-statements-use-an-array-to-look-up-the-wanted-value-based-on-the-key-you-have">🔥 Instead of writing repetitive `else if` statements, use an array to look up the wanted value based on the key you have</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Instead of writing repetitive `else if` statements, use an array to look up the wanted value based on the key you have" src="https://pbs.twimg.com/media/EanzWiHXsAAhshs.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>The code will be cleaner & more readable and you will see understandable exceptions if something goes wrong. No half-passing edge cases. <a href="https://t.co/zarUdjftUi">https://t.co/zarUdjftUi</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/use-custom-collections'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/use-custom-collections">🔥 Use custom collections</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Use custom collections" src="https://pbs.twimg.com/media/Ean3-8QXYAAmi7V.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Creating custom collections can be a great way to achieve more expressive syntax. Consider this example with order totals. <a href="https://t.co/vFBtUFlR7n">https://t.co/vFBtUFlR7n</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/when-a-relationship-is-already-loaded-and-cached-on-the-model-instance-youll-have-to-refresh-it'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/when-a-relationship-is-already-loaded-and-cached-on-the-model-instance-youll-have-to-refresh-it">🔥 When a relationship is already loaded and "cached" on the model instance, you'll have to refresh it</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="When a relationship is already loaded and "cached" on the model instance, you'll have to refresh it" src="https://pbs.twimg.com/media/Eic_JawXgAAEbYL.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p><code>$domain-&gt;refresh();</code> to refresh its attributes</p>
|
|
<p><code>$tenant-&gt;load('primary_domain');</code> to update the <code>primary_domain</code> relationship on the $tenant instance <a href="https://t.co/FdzT5rilEr">https://t.co/FdzT5rilEr</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/create-single-use-traits'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/create-single-use-traits">🔥 Create single-use traits</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Create single-use traits" src="https://pbs.twimg.com/media/Ean5BnEWkAEPUTe.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Adding methods to classes where they belong is cleaner than creating action classes for everything, but it can make the classes grow big</p>
|
|
<p>Consider using traits. They're meant <em>primarily</em> for code reuse, but there's nothing wrong with single-use traits <a href="https://t.co/dWWLNWuOoS">https://t.co/dWWLNWuOoS</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/people-underutilize-the-exception-handler'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/people-underutilize-the-exception-handler">🔥 People underutilize the exception handler</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="People underutilize the exception handler" src="https://pbs.twimg.com/media/Eic5sfxWAAY2ym2.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>You can tell the app what response to return when a specific exception is encountered.</p>
|
|
<p>This is the simplest example. There's many more use cases. <a href="https://t.co/diMoktScI3">https://t.co/diMoktScI3</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/be-friends-with-your-ide'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/be-friends-with-your-ide">🔥 Be friends with your IDE</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Be friends with your IDE" src="https://pbs.twimg.com/media/Ean6t2ZXgAEiJMa.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Install extensions, write annotations, use typehints. Your IDE will help you with getting your code working correctly, which lets you spend more energy on writing code that's also readable. <a href="https://t.co/xNMR2UHed7">https://t.co/xNMR2UHed7</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/laravel-nova-lets-you-show-different-resourcestoolscards-based-on-an-if-check'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/laravel-nova-lets-you-show-different-resourcestoolscards-based-on-an-if-check">🔥 Laravel Nova lets you show different resources/tools/cards/... based on an if check</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Laravel Nova lets you show different resources/tools/cards/... based on an if check" src="https://pbs.twimg.com/media/EidABmBXcAAto9_.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Extremely handy when you have multiple admin panels in a single app. <a href="https://t.co/3HvDb1Ae3N">https://t.co/3HvDb1Ae3N</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/avoid-helper-classes'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/avoid-helper-classes">🔥 Avoid helper *classes*</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Avoid helper *classes*" src="https://pbs.twimg.com/media/Ean2CnyWoAEZ3Ef.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Sometimes people put helpers into a class.</p>
|
|
<p>Beware, it can get messy. This is a class with only static methods used as helper functions. It's usually better to put these methods into classes with related logic or just keep them as global functions. <a href="https://t.co/iIcyReIW9N">https://t.co/iIcyReIW9N</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/create-variables-when-they-improve-readability'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/create-variables-when-they-improve-readability">🔥 Create variables when they improve readability</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Create variables when they improve readability" src="https://pbs.twimg.com/media/Ean0HJwWAAAZkDR.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>The opposite of the previous tip. Sometimes the value comes from a complex call and as such, creating a variable improves readability & removes the need for a comment.</p>
|
|
<p>Remember that context matters & your end goal is readability <a href="https://t.co/hwFni2X6zA">https://t.co/hwFni2X6zA</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/try-to-avoid-unnecessary-nesting-by-returning-a-value-early'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/try-to-avoid-unnecessary-nesting-by-returning-a-value-early">🔥 Try to avoid unnecessary nesting by returning a value early</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Try to avoid unnecessary nesting by returning a value early" src="https://pbs.twimg.com/media/EanzmPwXYAAoH2A.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Too much nesting & else statements tend to make code harder to read. <a href="https://t.co/PGueS91cgD">https://t.co/PGueS91cgD</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/extract-methods'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/extract-methods">🔥 Extract methods</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Extract methods" src="https://pbs.twimg.com/media/Ean1UORWkAE4UDD.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>If some method is too long or complex, and it's hard to understand what exactly is happening, split the logic into multiple methods. <a href="https://t.co/ljFm6RFk8i">https://t.co/ljFm6RFk8i</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/dont-split-lines-at-random-places-but-dont-make-them-too-long-either'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/dont-split-lines-at-random-places-but-dont-make-them-too-long-either">🔥 Don't split lines at random places, but don't make them too long either</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Don't split lines at random places, but don't make them too long either" src="https://pbs.twimg.com/media/Eanz0jnXsAAvkv1.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Opening an array with [ and indenting the values tends to work well. Same with long function parameter values.</p>
|
|
<p>Other good places to split lines are chained calls and closures. <a href="https://t.co/bnTL2I0Bxa">https://t.co/bnTL2I0Bxa</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/if-you-dont-like-the-double-indentation-of-vue-data-you-can-use-arrow-functions'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/if-you-dont-like-the-double-indentation-of-vue-data-you-can-use-arrow-functions">🔥 If you don't like the "double indentation" of Vue data(), you can use arrow functions</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="If you don't like the "double indentation" of Vue data(), you can use arrow functions" src="https://pbs.twimg.com/media/Edb2vN0XoAEnunt.png?name=small">
|
|
<img alt="If you don't like the "double indentation" of Vue data(), you can use arrow functions" src="https://pbs.twimg.com/media/Edb2vO8WoAAAcdX.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Left: double nesting
|
|
Right: arrow function <a href="https://t.co/6vxwuttW4G">https://t.co/6vxwuttW4G</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/laravel-telescope-is-great-for-so-many-things'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/laravel-telescope-is-great-for-so-many-things">🔥 Laravel Telescope is great for so many things</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Laravel Telescope is great for so many things" src="https://pbs.twimg.com/media/EidI3vCXgAIOCvY.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>One of them is examining sent emails ✉️</p>
|
|
<p>You usually don't need a service like Mailtrap. Just use the <code>log</code> mail driver and install Telescope.</p>
|
|
<p>(image stolen from the internet) <a href="https://t.co/odX4ZHzHE3">https://t.co/odX4ZHzHE3</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/have-a-single-source-of-truth-for-validation-rules'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/have-a-single-source-of-truth-for-validation-rules">🔥 Have a single source of truth for validation rules</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>If you validate some resource's attributes on multiple places, you definitely want to centralize these validation rules, so that you don't change them in one place but forget about the other places.</p>
|
|
<p><a href="https://t.co/qI1Q0HUEyK">https://t.co/qI1Q0HUEyK</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/this-one-is-less-obscure'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/this-one-is-less-obscure">🔥 This one is less obscure</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="This one is less obscure" src="https://pbs.twimg.com/media/EidvI20XcAA7MGY.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>The $loop variable.</p>
|
|
<p>It greatly complements Tailwind-styled tables.</p>
|
|
<p>Striped tables done easily 🎉 <a href="https://t.co/prm735AEuN">https://t.co/prm735AEuN</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/comparing-changes-on-saving-using'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/comparing-changes-on-saving-using">🔥 Comparing changes on 'saving' using:</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Comparing changes on 'saving' using:" src="https://pbs.twimg.com/media/EidZs1IWAAUgH0m.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>$model->getOriginal()</p>
|
|
<p>in Eloquent event listeners can be very useful.</p>
|
|
<p>One such use case is checking whether an order is locked. If it is, the only write action we permit is unlocking it. Only then can changes be made. <a href="https://t.co/rDD1ziOapj">https://t.co/rDD1ziOapj</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/dont-use-model-methods-to-retrieve-data'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/dont-use-model-methods-to-retrieve-data">🔥 Don't use model methods to retrieve data</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Don't use model methods to retrieve data" src="https://pbs.twimg.com/media/Ean58GjWAAAgqLq.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>If you want to retrieve some data from a model, create an accessor.</p>
|
|
<p>Keep methods for things that <em>change</em> the model in some way. <a href="https://t.co/3IpmbDuNF9">https://t.co/3IpmbDuNF9</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/use-collections-when-they-can-clean-up-your-code'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/use-collections-when-they-can-clean-up-your-code">🔥 Use collections when they can clean up your code</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Use collections when they can clean up your code" src="https://pbs.twimg.com/media/Ean8WekXkAEafMW.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Don't turn all arrays into collections just because Laravel offers them, but DO turn arrays into collections when you can make use of collection syntax to clean up your code. <a href="https://t.co/Jd8O3QFrP8">https://t.co/Jd8O3QFrP8</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/use-short-operators'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/use-short-operators">🔥 Use short operators</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Use short operators" src="https://pbs.twimg.com/media/Ean63YeXQAABhBd.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>PHP has many great operators that can replace ugly if checks. Memorize them. <a href="https://t.co/pGLyyNtwpj">https://t.co/pGLyyNtwpj</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/consider-single-action-controllers'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/consider-single-action-controllers">🔥 Consider single-action controllers</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Consider single-action controllers" src="https://pbs.twimg.com/media/Ean6Sn9XkAA-WKS.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>If you have a complex route action, consider moving it to a separate controller.</p>
|
|
<p>For OrderController::create, you'd create CreateOrderController.</p>
|
|
<p>Another solution is to move that logic to an action class — do what works best in your case. <a href="https://t.co/Rn6lFnhkVH">https://t.co/Rn6lFnhkVH</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/write-functional-code-when-it-benefits-you'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/write-functional-code-when-it-benefits-you">🔥 Write functional code when it benefits you</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Write functional code when it benefits you" src="https://pbs.twimg.com/media/Ean8cQUWoAEjdO3.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Functional code can both clean things up and make them impossible to understand. Refactor common loops into functional calls, but don't write stupidly complex reduce()s just to avoid writing a loop. There's a use case for both. <a href="https://t.co/1xVD2qwtkw">https://t.co/1xVD2qwtkw</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/use-docblocks-only-when-they-clarify-things'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/use-docblocks-only-when-they-clarify-things">🔥 Use docblocks only when they clarify things</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Use docblocks only when they clarify things" src="https://pbs.twimg.com/media/Ean8DcIXkAESZ_P.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Many people will disagree with this, because they do it. But it makes no sense.</p>
|
|
<p>There's no point in using docblocks when they don't give any extra information. If the typehint is enough, don't add a docblock.</p>
|
|
<p>That's just noise. <a href="https://t.co/Q2O6Kp0jzN">https://t.co/Q2O6Kp0jzN</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/create-action-classes'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/create-action-classes">🔥 Create action classes</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Create action classes" src="https://pbs.twimg.com/media/Ean0gvIWsAAIfxK.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Let's expand on the previous example. Sometimes, creating a class for a single action can clean things up.</p>
|
|
<p>Models should encapsulate the business logic related to them, but they shouldn't be too big. <a href="https://t.co/Mll37AAh5o">https://t.co/Mll37AAh5o</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/context-matters'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/context-matters">🔥 Context matters</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Context matters" src="https://pbs.twimg.com/media/Ean8vC0WAAEomIq.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Above I said that moving business logic to action/service classes is good. But context matters</p>
|
|
<p>Here's code design advice from a popular "Laravel best practices" repo. There's absolutely no reason to put a 3-line check into a class. That's just overengineered <a href="https://t.co/zOtKmaVtMu">https://t.co/zOtKmaVtMu</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/create-helper-functions'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/create-helper-functions">🔥 Create helper functions</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Create helper functions" src="https://pbs.twimg.com/media/Ean1ow4WoAAFjoT.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>If you repeat some code a lot, consider if extracting it to a helper function would make the code cleaner. <a href="https://t.co/2e4TtoVn9N">https://t.co/2e4TtoVn9N</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/if-youre-debugging-your-app-and-youd-like-to-examine-more-things-eg-the-stack-trace-executed-queries-app-context'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/if-youre-debugging-your-app-and-youd-like-to-examine-more-things-eg-the-stack-trace-executed-queries-app-context">🔥 If you're debugging your app and you'd like to examine more things - e.g. the stack trace, executed queries, app context, </a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="If you're debugging your app and you'd like to examine more things - e.g. the stack trace, executed queries, app context, " src="https://pbs.twimg.com/media/EidXEVXXgAofRdr.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>You can use ddd() instead of dd().</p>
|
|
<p>I tend to forget about this one, but it's super useful. <a href="https://t.co/hjVNOeLTRI">https://t.co/hjVNOeLTRI</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/dont-just-write-procedural-code-in-classes'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/dont-just-write-procedural-code-in-classes">🔥 Don't just write procedural code in classes</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Don't just write procedural code in classes" src="https://pbs.twimg.com/media/Ean2u-YX0AEmwEd.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>This ties the previous tweet with the other tips here. OOP exists to make your code more readable, use it. Don't just write 400 line long procedural code in controller actions.</p>
|
|
<p>Here's code from my first Laravel project 😬 <a href="https://t.co/2DeGX148Wh">https://t.co/2DeGX148Wh</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/use-custom-config-files'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/use-custom-config-files">🔥 Use custom config files</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Use custom config files" src="https://pbs.twimg.com/media/Ean6FxnXkAAXDsl.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>You can store things like "results per page" in config files. Don't add them to the app config file though. Create your own. In my e-commerce project, I use config/shop.php. <a href="https://t.co/kXkte9Ysrv">https://t.co/kXkte9Ysrv</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/create-query-scopes-for-complex-wheres'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/create-query-scopes-for-complex-wheres">🔥 Create query scopes for complex where()s</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Create query scopes for complex where()s" src="https://pbs.twimg.com/media/Ean5ymtXgAEvlxm.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Rather than writing complex where() clauses, create query scopes with expressive names.</p>
|
|
<p>This will make your e.g. controllers have to know less about the database structure and your code will be cleaner. <a href="https://t.co/mqxugYM4oG">https://t.co/mqxugYM4oG</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/dont-create-variables-when-you-can-just-pass-the-value-directly-httpstcos8vozn7aor'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/dont-create-variables-when-you-can-just-pass-the-value-directly-httpstcos8vozn7aor">🔥 Don't create variables when you can just pass the value directly. https://t.co/S8VOzn7aOr</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Don't create variables when you can just pass the value directly. https://t.co/S8VOzn7aOr" src="https://pbs.twimg.com/media/Eanz9WJWkAAeoT2.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/dont-use-abbreviations'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/dont-use-abbreviations">🔥 Don't use abbreviations</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Don't use abbreviations" src="https://pbs.twimg.com/media/Ean4TBBXgAAMab3.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Don't think that long variable/method names are wrong. They're not. They're expressive.</p>
|
|
<p>Better to call a longer method than a short one and check the docblock to understand what it does</p>
|
|
<p>Same with variables. Don't use nonsense 3-letters abbreviations <a href="https://t.co/a23I1L7TtW">https://t.co/a23I1L7TtW</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/when-im-converting-data-into-a-different-structure-one-thing-i-like-to-do-is-annotate-how-the-structure-looks-at-each-point-of-the-process'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/when-im-converting-data-into-a-different-structure-one-thing-i-like-to-do-is-annotate-how-the-structure-looks-at-each-point-of-the-process">🔥 When I'm converting data into a different structure, one thing I like to do is annotate how the structure looks at each point of the process</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="When I'm converting data into a different structure, one thing I like to do is annotate how the structure looks at each point of the process" src="https://pbs.twimg.com/media/EinfW11XgAE0y7W.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>I developed this habit when I was building a lot of data conversion scripts in Python, but it's 100% applicable in PHP as well. <a href="https://t.co/fGnbAwoj26">https://t.co/fGnbAwoj26</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/create-custom-blade-directives-for-business-logic'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/create-custom-blade-directives-for-business-logic">🔥 Create custom Blade directives for business logic</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Create custom Blade directives for business logic" src="https://pbs.twimg.com/media/Ean7bYSXkAIwDIR.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>You can make your Blade templates more expressive by creating custom directives. For example, rather than checking if the user has the admin role, you could use @admin. <a href="https://t.co/FY5CMi4gVP">https://t.co/FY5CMi4gVP</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/you-can-create-dynamic-relationships-this-relationship-is-based-on-a-column-thats-added-using-a-subquery-in-a-scope'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/you-can-create-dynamic-relationships-this-relationship-is-based-on-a-column-thats-added-using-a-subquery-in-a-scope">🔥 You can create dynamic relationships — this relationship is based on a column that's added using a subquery, in a scope</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="You can create dynamic relationships — this relationship is based on a column that's added using a subquery, in a scope" src="https://pbs.twimg.com/media/EidrdqwWkAIy4oN.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>And so much more. <a href="https://t.co/EqVABRXKQJ">https://t.co/EqVABRXKQJ</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/this-wont-fit-into-one-tweet-but-theres-so-much-cool-stuff-you-can-do-with-eloquent'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/this-wont-fit-into-one-tweet-but-theres-so-much-cool-stuff-you-can-do-with-eloquent">🔥 This won't fit into one tweet but there's so much cool stuff you can do with Eloquent</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="This won't fit into one tweet but there's so much cool stuff you can do with Eloquent" src="https://pbs.twimg.com/media/Eidq5A3XsAAM9lA.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>You DON'T have to go raw SQL when you hit a performance issue with Eloquent. There's so many "secret" techniques.</p>
|
|
<p>Example: You can create scopes to add specific selects to your queries. <a href="https://t.co/YrIWlKf2K7">https://t.co/YrIWlKf2K7</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/if-you-didnt-know-at-laravellivewire-now-triggers-updated-and-updating-hooks-for-nested-properties-which-works-with-both-array-and-model-properties-httpstco0rtwrpgfld'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/if-you-didnt-know-at-laravellivewire-now-triggers-updated-and-updating-hooks-for-nested-properties-which-works-with-both-array-and-model-properties-httpstco0rtwrpgfld">🔥 If you didn't know, @LaravelLivewire now triggers "updated" and "updating" hooks for nested properties, which works with both array and model properties! https://t.co/0RtwRPgfld</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="If you didn't know, @LaravelLivewire now triggers "updated" and "updating" hooks for nested properties, which works with both array and model properties! https://t.co/0RtwRPgfld" src="https://pbs.twimg.com/media/EiXw7FcXYAEGzFy.jpg?name=small">
|
|
<img alt="If you didn't know, @LaravelLivewire now triggers "updated" and "updating" hooks for nested properties, which works with both array and model properties! https://t.co/0RtwRPgfld" src="https://pbs.twimg.com/media/EiXw7h3WAAEjT9F.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/you-can-add-a-tags-method-to-a-job-anything-you-return-from-this-method-will-be-displayed-in-horizon'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/you-can-add-a-tags-method-to-a-job-anything-you-return-from-this-method-will-be-displayed-in-horizon">🔥 You can add a tags() method to a job. Anything you return from this method will be displayed in Horizon</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="You can add a tags() method to a job. Anything you return from this method will be displayed in Horizon" src="https://pbs.twimg.com/media/EidtAYaXkAEjAl-.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Very useful if you want to tag jobs with things like the user/tenant id. <a href="https://t.co/cpg1Zp5BPu">https://t.co/cpg1Zp5BPu</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/example-deleting-associated-files-on-deletion-httpstco4j8uzu0zyy'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/example-deleting-associated-files-on-deletion-httpstco4j8uzu0zyy">🔥 Example: Deleting associated files on deletion. https://t.co/4j8UZU0ZYy</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Example: Deleting associated files on deletion. https://t.co/4j8UZU0ZYy" src="https://pbs.twimg.com/media/EidbEGZXYAA6q3G.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/import-namespaces-instead-of-using-aliases'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/import-namespaces-instead-of-using-aliases">🔥 Import namespaces instead of using aliases</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Import namespaces instead of using aliases" src="https://pbs.twimg.com/media/Ean5otqXYAA4QPR.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Sometimes you may have multiple classes with the same name. Rather than importing them with an alias, import the namespaces. <a href="https://t.co/O14vx38oan">https://t.co/O14vx38oan</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/eloquent-listeners-are-awesome'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/eloquent-listeners-are-awesome">🔥 Eloquent listeners are awesome</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Eloquent listeners are awesome" src="https://pbs.twimg.com/media/EidaLtrXcAU0nIG.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Example: Default value set on creation. <a href="https://t.co/eXVC8WR0xV">https://t.co/eXVC8WR0xV</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/laravel-migrations-have-a-very-nice-syntax-for-foreign-keys'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/laravel-migrations-have-a-very-nice-syntax-for-foreign-keys">🔥 Laravel migrations have a very nice syntax for foreign keys</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>I didn't know about this for so long.</p>
|
|
<p>Instead of:
|
|
$table->unsignedBigInteger('user_id');
|
|
$table->foreign('user_id')->references('id')->on('users');</p>
|
|
<p>You do:
|
|
$table->foreignId('user_id')->constrained();</p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/you-can-use-wherexandy-in-eloquent'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/you-can-use-wherexandy-in-eloquent">🔥 You can use where{X}and{Y}() in Eloquent</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="You can use where{X}and{Y}() in Eloquent" src="https://pbs.twimg.com/media/EidOOuTXYAYMtI9.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Not recommended in most cases, but interesting.</p>
|
|
<p>(image stolen from the internet) <a href="https://t.co/8kKmRUYi8e">https://t.co/8kKmRUYi8e</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/relevant-for-people-building-packages'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/relevant-for-people-building-packages">🔥 Relevant for people building packages 📦</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Relevant for people building packages 📦" src="https://pbs.twimg.com/media/EidBy75XsA4CZGx.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>It's IMO better to use static properties and have "self-contained" behavior & configuration. Than to have a billion config keys. Especially when building large packages.</p>
|
|
<p>Makes the package more extensible, by consisting of atomic parts <a href="https://t.co/tyucZmkmsz">https://t.co/tyucZmkmsz</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/dedicate-a-weekend-towards-learning-proper-oop'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/dedicate-a-weekend-towards-learning-proper-oop">🔥 Dedicate a weekend towards learning proper OOP</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Know the difference between static/instance methods & variables and private/protected/public visibility. Also learn how Laravel uses magic methods.</p>
|
|
<p>You don't need this as a beginner, but as your code grows, it's crucial.</p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/avoid-queries-in-blade-when-possible'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/avoid-queries-in-blade-when-possible">🔥 Avoid queries in Blade when possible</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Avoid queries in Blade when possible" src="https://pbs.twimg.com/media/Ean7jvPWkAAp2_6.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Sometimes you may want to execute DB queries in blade. There are some ok use cases for this, such as in layout files.</p>
|
|
<p>But if it's a view returned by a controller, pass the data in the view data instead. <a href="https://t.co/olodRS3N9s">https://t.co/olodRS3N9s</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/you-can-return-false-from-a-ing-eloquent-event-listener-creating-updating-saving-deleting-to-cancel-the-action'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/you-can-return-false-from-a-ing-eloquent-event-listener-creating-updating-saving-deleting-to-cancel-the-action">🔥 You can return "false" from a -ing() Eloquent event listener (creating, updating, saving, deleting) to cancel the action</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="You can return "false" from a -ing() Eloquent event listener (creating, updating, saving, deleting) to cancel the action" src="https://pbs.twimg.com/media/Eidmle3WoAI72Yk.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>This is similar to how I was throwing an exception based on certain things in the example with order locking. <a href="https://t.co/fg5z2TWGZx">https://t.co/fg5z2TWGZx</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/you-can-explicitly-bind-objects-to-routes-you-dont-have-to-use-route-model-binding-only-custom-objects-work-perfectly-well-too'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/you-can-explicitly-bind-objects-to-routes-you-dont-have-to-use-route-model-binding-only-custom-objects-work-perfectly-well-too">🔥 You can explicitly bind objects to routes. You don't have to use route model binding only. Custom objects work perfectly well too</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="You can explicitly bind objects to routes. You don't have to use route model binding only. Custom objects work perfectly well too" src="https://pbs.twimg.com/media/EidyDmfWsAI14-C.png?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>This example is from Tenancy v2 when we had an ActiveRecord-style custom Tenant object. <a href="https://t.co/kydWSrcmer">https://t.co/kydWSrcmer</a></p>
|
|
</section>
|
|
</article>
|
|
<article class="border-b-2 border-gray-200 py-16" x-data @click="window.location.href = 'http://127.0.0.1:6969/tips/heres-another-example-of-the-model-state-stuff-mentioned-above'">
|
|
<h1 class="text-3xl font-medium">
|
|
<a href="http://127.0.0.1:6969/tips/heres-another-example-of-the-model-state-stuff-mentioned-above">🔥 Here's another example of the Model state stuff mentioned above</a>
|
|
</h1>
|
|
|
|
<div class="mt-4 flex justify-center w-1/2 gap-1 flex-wrap mx-auto">
|
|
<img alt="Here's another example of the Model state stuff mentioned above" src="https://pbs.twimg.com/media/EidDSDcXYAA_7XD.jpg?name=small">
|
|
</div>
|
|
|
|
<section role="article" class="mt-8 text-xl prose mx-auto">
|
|
<p>Except...</p>
|
|
<p>It's multi-tenant!</p>
|
|
<p>Tip 7: It's incredibly easy to use <a href="https://t.co/XDsbINZGoO">https://t.co/XDsbINZGoO</a> with Tinker 😎 <a href="https://t.co/kyk0A0te2M">https://t.co/kyk0A0te2M</a></p>
|
|
</section>
|
|
</article>
|
|
</section>
|
|
</main>
|
|
|
|
<footer class="space-y-2 text-gray-700 text-sm">
|
|
<p>Found an error? Contact us at <a href="mailto:hello@laravel-code.tips" class="link">support@laravel-code.tips</a>.</p>
|
|
<p>Want to share a tip? Submit it <a href="https://airtable.com/shrBX2ZAfnuAXh3up" target="_blank" class="link">here</a>.</p>
|
|
</footer>
|
|
</div>
|
|
</body>
|
|
</html>
|