PHP code example of larabra / laravel-media-library-input

1. Go to this page and download the library: Download larabra/laravel-media-library-input 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/ */

    

larabra / laravel-media-library-input example snippets


// app\Model\News.php
namespace App\Models;

use Illuminate\Database\Eloquent\Model as Model;
use Larabra\LaravelMediaLibraryInput\Casts\MediaCastAttribute; // <---
use Larabra\LaravelMediaLibraryInput\Models\MediableModel; // <---
use Spatie\MediaLibrary\HasMedia;

class News extends Model implements HasMedia
{
    use InteractsWithMedia;
    use MediableModel; // <--- create/add medias with form submit

    // "cover" is a fake field, so add it as append and create its cast

    protected $appends = [
        'cover',
    ];

    protected $casts = [
        'cover' => MediaCastAttribute::class,
    ];
    // ...
}

// app\Http\Controllers\NewsController.php


namespace App\Http\Controllers;

use App\Repositories\NewsRepository;
use Larabra\LaravelMediaLibraryInput\Http\Controllers\MediableController;

class NewsController extends AppBaseController
{
    use MediableController; // <--- add controller methods to manager medias

    /** @var  NewsRepository */
    private $newsRepositorysitory;

    public function __construct(NewsRepository $newsRepository)
    {
        $this->newsRepository = $newsRepository;
    }