1. Go to this page and download the library: Download yanmarques/lincable 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/ */
yanmarques / lincable example snippets
/**
* Upload an image to application.
*
* @param ImageFileRequest $image
* @return Response
*/
public function upload(ImageFileRequest $image)
{
// The ImageFileRequest contains the current request.
$request = $image->getRequest();
// Create the image model on database with request attributes.
$image = \App\Image::create($request->all());
// The model uses the lincable trait, which has the link method
// that store the file and generate a url for the model.
$image->link($image);
$image->preview; // https://your-cloud-storage.com/media/foo/123/bar/321/e1wPJQmQpFPOaQ238fglQHnrxzv2uK8joPyozv9i.jpg
}
/**
* Upload a image to application.
*
* @param \App\FileRequests\ImageFileRequest $image
* @return response
*/
public function upload(ImageFileRequest $image)
use Image;
use Lincable\Http\FileRequest;
class ImageFileRequest extends FileRequest
{
protected function rules()
{
return 'en saved an the changes will reflect.
Image::make($file)->resize(600, 400)->save();
}
}
$colonParser->addFormatter(function (Request $request) {
if ($request->user()->isBoss()) {
return 'boss-location';
}
return 'baz';
}, 'customLocation');
$url = 'foo/:customLocation';
// Is user on request is the boss.
'foo/boss-location/dqiojqwdij.zip'
// The user on request is not the boss.
'foo/baz/dqiojqwdij.zip';
namespace App\Formatters;
...
class GetApiIdFormatter
{
/**
* Attributes initialized here.
*/
public function __construct(ApiClient $api, Config $params)
{
$this->api = $api;
$this->setConfig($config);
// More function tasks.
}
/**
* More complex methods here.
*/
public function format(Request $request)
{
return $this->getIdForUser($request->user());
}
}
return [
...
default_parsers => [
\Lincable\Parsers\ColonParser::class => [
\Lincable\Formatters\YearFormatter::class,
\Lincable\Formatters\DayFormatter::class,
\Lincable\Formatters\MonthFormatter::class,
\Lincable\Formatters\RandomFormatter::class,
\Lincable\Formatters\TimestampsFormatter::class,
/**
* Here we add the formatter
*/
\App\Formatters\GetApiIdFormatter::class
]
]
];
$file->toArray(); // ['id' => 123, 'foo_id' => 321,'preview' => null]
$urlConf = new UrlConf; // Create the model url configuration.
$urlConf->push(File::class, ':year/:id/:month/:foo_id');
$generator = new UrlGenerator($urlCompiler, $parsers, $urlConf);
$preview = $generator->forModel($file)->generate(); // Generate the url for the model from configuration.
$preview; // 'https://your-disk-storage.com/2018/123/07/321/HJSxDckZZcMbc8AiWxzlg1Jx2gBVYO6kBqhna6Td.zip'