PHP code example of optimistdigital / nova-notes-field
1. Go to this page and download the library: Download optimistdigital/nova-notes-field 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/ */
optimistdigital / nova-notes-field example snippets
use Outl1ne\NovaNotesField\Traits\HasNotes;
class ExampleModel extends Model
{
use HasNotes;
}
use Outl1ne\NovaNotesField\NotesField;
class SomeResource extends Resource
{
// ...
public function fields(Request $request)
{
return [
// ...
NotesField::make('Notes')
->placeholder('Add note') // Optional
->addingNotesEnabled(false) // Optional
->fullWidth(), // Optional
]
}
}
/**
* Creates a new note and attaches it to the model.
*
* @param string $note The note text which can contain raw HTML.
* @param bool $user Enables or disables the use of `Auth::user()` to set as the creator.
* @param bool $system Defines whether the note is system created and can be deleted or not.
* @return \Outl1ne\NovaNotesField\Models\Note
**/
public function addNote($note, $user = true, $system = true)
/**
* Edit a note with the given ID and text.
*
* @param int|string $noteId The ID of the note to edit.
* @param string $text The note text which can contain raw HTML.
* @return \Outl1ne\NovaNotesField\Models\Note
**/
public function editNote($noteId, $text)
use Illuminate\Support\Facades\Gate;
use Outl1ne\NovaNotesField\Models\Note;
// ...
public function boot()
{
Gate::define('edit-nova-note', function ($user, Note $note) {
// Do whatever here to add custom edit authorization logic, ie:
return $note->created_by === $user->id || $user->isAdmin;
});
Gate::define('delete-nova-note', function ($user, Note $note) {
// Do whatever here to add custom delete authorization logic, ie:
return $note->created_by === $user->id || $user->isAdmin;
});
}