oddvalue / laravel-drafts Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hi,
Perhaps I am missing something.
I am using Filament 2 with a resource route called TicketResource
, I cannot edit or see model entries that are is_published
= 0
aka in draft. They go to 404 unless they are published. As the creator of the draft I would be able to see and interact with.
In my TicketResource
I have:
public static function getPages(): array
{
return [
'index' => Pages\ListTickets::route('/'),
'create' => Pages\CreateTicket::route('/create'),
'view' => Pages\ViewTicket::route('/{record}'),
'edit' => Pages\EditTicket::route('/{record}/edit'),
'activities' => Pages\ListTicketActivities::route('/{record}/activities'),
];
}
Can you assist with what I may be missing?
Hello, thank you for your work on this library.
Here's a failing test, which I thought would pass:
it('does not create multiple published records', function () {
$post = Post::factory()->create();
$post->saveAsDraft();
$post->draft->publish()->save();
$this->assertCount(1, Post::withoutDrafts()->get());
// Failed asserting that actual size 2 matches expected size 1.
});
If this is the expected behaviour, how do I get only the latest published instances?
Hi there,
When using $model->update()
the updating method is not firing thus not creating a new revision of an updated model.
$this->model->update([
'title' => $this->request->title,
'content' => $this->request->content,
'meta_title' => $this->request->meta_title,
'meta_description' => $this->request->meta_description,
'slug' => $this->request->slug,
'parent_id' => $this->request->parent_id,
'user_id' => auth()->id(),
]);
When using the create() method a new record is added with is_published set to 1 and also is_current set to 1 and creates a new uuid for the post and doesn't create any form of relationship to the previous - im not sure if im doing something wrong or if im misunderstanding the docs.
Ultimately, when I update a record, a new revision should be made and by default marked as is_published and is_current and then the previous to be unmarked.
The getCurrentUser method of the LaravelDrafts class informs that it returns an Authenticatable type, although based on the Trait code, it can return a null result
I think it should say
public function getCurrentUser():? Authenticatable
[2024-04-12 14:12:47] local.ERROR: Oddvalue\LaravelDrafts\LaravelDrafts::getCurrentUser(): Return value must be of type Illuminate\Contracts\Auth\Authenticatable, null returned {"exception":"[object] (TypeError(code: 0): Oddvalue\\LaravelDrafts\\LaravelDrafts::getCurrentUser(): Return value must be of type Illuminate\\Contracts\\Auth\\Authenticatable, null returned at /var/www/html/vendor/oddvalue/laravel-drafts/src/LaravelDrafts.php:15)
[stacktrace]
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(357): Oddvalue\\LaravelDrafts\\LaravelDrafts->getCurrentUser()
#1 /var/www/html/vendor/oddvalue/laravel-drafts/src/Concerns/HasDrafts.php(329): Illuminate\\Support\\Facades\\Facade::__callStatic()
#2 /var/www/html/vendor/oddvalue/laravel-drafts/src/Concerns/HasDrafts.php(55): App\\Models\\User->setPublisher()
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(458): App\\Models\\User::Oddvalue\\LaravelDrafts\\Concerns\\{closure}()
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(286): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}()
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(266): Illuminate\\Events\\Dispatcher->invokeListeners()
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(232): Illuminate\\Events\\Dispatcher->dispatch()
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php(215): Illuminate\\Events\\Dispatcher->until()
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1286): Illuminate\\Database\\Eloquent\\Model->fireModelEvent()
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1142): Illuminate\\Database\\Eloquent\\Model->performInsert()
#10 /var/www/html/vendor/oddvalue/laravel-drafts/src/Concerns/HasDrafts.php(296): Illuminate\\Database\\Eloquent\\Model->save()
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1026): App\\Models\\User->save()
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/helpers.php(359): Illuminate\\Database\\Eloquent\\Builder->Illuminate\\Database\\Eloquent\\{closure}()
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1025): tap()
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(584): Illuminate\\Database\\Eloquent\\Builder->create()
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1729): Illuminate\\Database\\Eloquent\\Builder->Illuminate\\Database\\Eloquent\\{closure}()
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(584): Illuminate\\Database\\Eloquent\\Builder->withSavepointIfNeeded()
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(571): Illuminate\\Database\\Eloquent\\Builder->createOrFirst()
#18 /var/www/html/routes/web.php(6): Illuminate\\Database\\Eloquent\\Builder->firstOrCreate()
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/CallableDispatcher.php(40): Illuminate\\Routing\\RouteFileRegistrar->{closure}()
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(238): Illuminate\\Routing\\CallableDispatcher->dispatch()
#21 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(209): Illuminate\\Routing\\Route->runCallable()
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(806): Illuminate\\Routing\\Route->run()
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(88): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#27 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle()
#28 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#29 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle()
#30 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#31 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest()
#32 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Session\\Middleware\\StartSession->handle()
#33 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#34 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle()
#35 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(75): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#36 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle()
#37 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#38 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(805): Illuminate\\Pipeline\\Pipeline->then()
#39 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(784): Illuminate\\Routing\\Router->runRouteWithinStack()
#40 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(748): Illuminate\\Routing\\Router->runRoute()
#41 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(737): Illuminate\\Routing\\Router->dispatchToRoute()
#42 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\\Routing\\Router->dispatch()
#43 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#44 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#45 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#46 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#47 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#48 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(51): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#49 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#50 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#51 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\ValidatePostSize->handle()
#52 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(110): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#53 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#54 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#55 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\HandleCors->handle()
#56 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#57 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#58 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then()
#60 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#61 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1168): Illuminate\\Foundation\\Http\\Kernel->handle()
#62 /var/www/html/public/index.php(17): Illuminate\\Foundation\\Application->handleRequest()
#63 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php(16): require_once('...')
#64 {main}
"}
Please excuse me if this is a misunderstanding on my part - I've tried applying the middleware in a few different ways, but am having some issues getting it to work successfully with route binding with models.
For example (imagine item ID 123 is a draft):
Route::withDrafts(function (): void {
Route::get('/item/{item}', function() {
dd(Item::find(123));
});
});
This works fine. However, something along the lines of:
Route::withDrafts(function (): void {
Route::get('/item/{item}', ItemController::class, 'edit');
});
...
class ItemController {
public function edit(Item $item)
{
dd($item);
}
}
results in a 404. Setting the is_published field to 1 on the item in question allows the page to load, so the route works, it just isn't obeying the middleware and including drafts when binding the item model.
// App\Http\Controllers\AlbumController
/**
* Show the form for editing the specified resource.
*/
public function edit(int $album): \Inertia\Response
{
$album = Album::current()->findOrFail($album);
return Inertia::render('Dashboard/Album/Edit', [
'album' => $album,
]);
}
Maybe docblock on HasDrafts.php line 18
is causing the issue. Any help?
Environment:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.