This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\DB; | |
class TransactionEncapsulation | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function exportCSV() | |
{ | |
header('Content-type: text/csv'); | |
header('Content-Disposition: attachment; filename=products.csv'); | |
header('Pragma: no-cache'); | |
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | |
header('Expires: 0'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In the Post model | |
class Post extends Model | |
{ | |
public function user() | |
{ | |
return $this->belongsTo(User::class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$posts = Post::filter($filters)->get(); | |
$groupBy = $filters['groupBy'] ?? 'week'; | |
$posts->groupBy(function ($post) use ($groupBy) { | |
return match ($groupBy) { | |
'day' => $post->published_at->format('D d M Y'), | |
// 📅 Group by day, format 'Day Date Month Year' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Database\Eloquent\Builder; | |
use Illuminate\Support\Arr; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function up(): void | |
{ | |
// Method 1: Adding 'team_id' Foreign Key to Different Tables One by One | |
Schema::table('users', function (Blueprint $table) { | |
$table->foreignIdFor(Team::class)->nullable(); | |
}); | |
Schema::table('posts', function (Blueprint $table) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Traits\Models; | |
use App\Models\Team; | |
use Illuminate\Database\Eloquent\Builder; | |
trait BelongsToTeam | |
{ | |
// This method is executed when a new model is being created. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Livewire; | |
use Livewire\Component; | |
use Livewire\Attributes\Renderless; | |
use App\Traits\HasFilteredReports; | |
class Reports extends Component | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Livewire; | |
use App\Models\Post; | |
use Livewire\Component; | |
class PostList extends Component | |
{ | |
public $offset = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 🎉 Birthday Check Function 🚀 | |
use Carbon\Carbon; | |
function checkBirthday($birthday) | |
{ | |
return Carbon::now()->isSameDay($birthday) | |
? "🎉🥳 Happy Birthday! 🎂 Best wishes for an amazing year ahead! 🚀" | |
: "🎈 No birthday today. Make it an awesome day anyway! 🌟"; | |
} |
OlderNewer