PHP code example of nathanheffley / laravel-watermelon
1. Go to this page and download the library: Download nathanheffley/laravel-watermelon library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nathanheffley / laravel-watermelon example snippets
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddWatermelonIdToTasksTable extends Migration
{
public function up()
{
Schema::table('tasks', function (Blueprint $table) {
$table->string('watermelon_id')->after('id')->unique();
});
}
public function down()
{
Schema::table('tasks', function (Blueprint $table) {
$table->dropColumn('watermelon_id');
});
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use NathanHeffley\LaravelWatermelon\Traits\Watermelon;
class Task extends Model
{
use SoftDeletes, Watermelon;
}
class Task extends Model
{
use SoftDeletes, Watermelon;
protected array $watermelonAttributes = [
'content',
'is_completed',
];
}
use Illuminate\Support\Facades\Auth;
class Task extends Model
{
// ...
public function scopeWatermelon($query)
{
return $query->where('user_id', Auth::user()->id);
}
}