1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-02-24 03:03:55 +01:00
LinkAce/app/Repositories/ListRepository.php

59 lines
1.1 KiB
PHP
Raw Normal View History

2019-10-29 16:59:03 +01:00
<?php
namespace App\Repositories;
use App\Models\LinkList;
use Exception;
2019-10-29 16:59:03 +01:00
use Illuminate\Support\Facades\Log;
/**
* Class ListRepository
*
* @package App\Repositories
*/
2019-10-29 16:59:03 +01:00
class ListRepository
{
/**
* @param array $data
* @return LinkList
*/
public static function create(array $data): LinkList
{
$data['user_id'] = auth()->user()->id;
$data['name'] = str_replace(',', '', $data['name']);
2019-10-29 16:59:03 +01:00
return LinkList::create($data);
}
/**
* @param LinkList $list
* @param array $data
* @return LinkList
*/
public static function update(LinkList $list, array $data): LinkList
{
$data['name'] = str_replace(',', '', $data['name']);
2019-10-29 16:59:03 +01:00
$list->update($data);
return $list;
}
/**
* @param LinkList $list
* @return bool
*/
public static function delete(LinkList $list): bool
{
try {
$list->links()->detach();
$list->delete();
} catch (Exception $e) {
2019-10-29 16:59:03 +01:00
Log::error($e);
return false;
}
return true;
}
}