Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\Eloquent;
4
 
5
use RuntimeException;
6
 
7
class JsonEncodingException extends RuntimeException
8
{
9
    /**
10
     * Create a new JSON encoding exception for the model.
11
     *
12
     * @param  mixed  $model
13
     * @param  string  $message
14
     * @return static
15
     */
16
    public static function forModel($model, $message)
17
    {
18
        return new static('Error encoding model ['.get_class($model).'] with ID ['.$model->getKey().'] to JSON: '.$message);
19
    }
20
 
21
    /**
22
     * Create a new JSON encoding exception for the resource.
23
     *
24
     * @param  \Illuminate\Http\Resources\Json\JsonResource  $resource
25
     * @param  string  $message
26
     * @return static
27
     */
28
    public static function forResource($resource, $message)
29
    {
30
        $model = $resource->resource;
31
 
32
        return new static('Error encoding resource ['.get_class($resource).'] with model ['.get_class($model).'] with ID ['.$model->getKey().'] to JSON: '.$message);
33
    }
34
 
35
    /**
36
     * Create a new JSON encoding exception for an attribute.
37
     *
38
     * @param  mixed  $model
39
     * @param  mixed  $key
40
     * @param  string  $message
41
     * @return static
42
     */
43
    public static function forAttribute($model, $key, $message)
44
    {
45
        $class = get_class($model);
46
 
47
        return new static("Unable to encode attribute [{$key}] for model [{$class}] to JSON: {$message}.");
48
    }
49
}