1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-02-23 18:53:13 +01:00
LinkAce/app/Repositories/NoteRepository.php
2021-05-10 13:51:09 +02:00

52 lines
913 B
PHP

<?php
namespace App\Repositories;
use App\Models\Note;
use Exception;
use Illuminate\Support\Facades\Log;
class NoteRepository
{
/**
* @param array $data
* @return Note
*/
public static function create(array $data): Note
{
$data['user_id'] = auth()->user()->id;
return Note::create($data);
}
/**
* @param Note $note
* @param array $data
* @return Note
*/
public static function update(Note $note, array $data): Note
{
$data['is_private'] = $data['is_private'] ?? false;
$note->update($data);
return $note;
}
/**
* @param Note $note
* @return bool
*/
public static function delete(Note $note): bool
{
try {
$note->delete();
} catch (Exception $e) {
Log::error($e);
return false;
}
return true;
}
}