Giter Club home page Giter Club logo

laravel-shareable-models's Introduction

Laravel Shareable Models

Generate shareable links from your Eloquent models.

Documentation

You can find the full documentation Here.

License

MIT

laravel-shareable-models's People

Contributors

dependabot[bot] avatar filipegar avatar github-actions[bot] avatar hackel avatar ksassnowski avatar laravel-shift avatar subodhdahal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-shareable-models's Issues

QueryException with invalid UUID

Hello.

I've been testing your package to replace dwightwatson/autologin on my project and tried to supply an invalid uuid value to the url.
The project is running with a postgres database, that have native field support to uuids. In this case, laravel throws a Illuminate\Database\QueryException.

To solve this, I added a try/catch block to the Route::bind call on the ServiceProvider as below:
The idea is to replace the QueryException with the ModelNotFoundException, that will be handled by Laravel and will generate a proper 404 response.

<?php

Route::bind('shareable_link', function ($value) {
    try {
	return ShareableLink::where('uuid', $value)->firstOrFail();
    } catch(QueryException $e) {
	throw new ModelNotFoundException($e->getMessage());
    }
});

Do you have a better approach to this? May I open a pull request?

Can't get the expired route to work.

Hello,
I'm trying to get the expired link route to work properly, and keep getting a 404 error screen. Cannot seem to get it to render a view. Here is what is inside my routes/web.php:

Route::domain('{cname}.' . config('routing.domain'))->middleware('subdomain')->group(function () {

    Route::get('/interview/{shareable_link}', function (ShareableLink $link) {
        $controller = new InterviewController($link);
        return $controller->show();
    })->middleware('shared')->name('interview.index');

    Route::get('/interview/{shareable_link}/next', function (ShareableLink $link) {
        $controller = new InterviewController($link);
        return $controller->next();
    })->middleware('shared')->name('interview.next');

    Route::post('/interview/{shareable_link}/record', function (ShareableLink $link, Request $request) {
        $controller = new InterviewController($link);
        return $controller->record($request);
    })->middleware('shared')->name('interview.record');

//    Route::get('/interview/expired', 'InterviewController@expired')->middleware('shared')->name('interview.expired');

    Route::get('/interview/expired', function () {
        dd('here!');
    })->name('interview.expired');

});

The config file has the shareable-models.php has 'expired' => '/interview/expired' redirect set. All other shareable routes within group work just fine. When specifying a UUID of an expired shareable link I get redirected to /interview/expired route, but always with a 404. I had also tried to Route::view, which is ultimately all I want in the first place -- just a page alerting the user that the link had expired. And as a test, it never outputs 'here!' in my temporary route above. Any ideas would be appreciated.

Thank you in advance!

Class 'App\Http\Controllers\ShareableLink' not found

Not quite sure why this is happening as I have put it in my providers, and after that I ran php artisan config:clear and cache:clear.
Getting this:
Class 'App\Http\Controllers\ShareableLink' not found

Here's the code I'm trying to run
ShareableLink::buildFor($entry) ->setActive() ->build();

route is not working

There are some problems with documentation.

  1. the entry to be put in the routes file has a typo:
Route::get('shared/{shareable_link}', ['middleware' => 'shared', function (ShareableLink $link) {
    return $link->shareable;
});

A closing bracket ] is missing.

  1. the route doesn't work anyway. To be honest I have no idea why.
    I tried to link the route to middleware using an alternative syntax
Route::get('shared/{shareable_link}', function (Sassnowski\LaravelShareableModel\Shareable\ShareableLink $link) {
    return 'test OK';
})->middleware('shared');

But to no result.

Maybe you could run the package on a clean new instance of Laravel 5.5?

  1. In docs here https://ksassnowski.gitbooks.io/shareable-models/content/getting-started.html
    it would be nicer if you mention that the user should declare the class in the header of the controller file:
    use Sassnowski\LaravelShareableModel\Shareable\ShareableLink;

The package should be great, anyway! Thank you.

Peter

How to get the link from a model?

This is not explained at all. How am I suppose to get the actual link from a model? I have the model Article, and I want to find Article 1's link. How do I do this?

[Question] Best Practice

Dear Kai,

thank you so much for this awesome piece of code - it is really helpful and i managed to implement it in my current api project. However, I have a question regarding "best practice" with this package. Maybe you can help or give advice?

Consider the following (simplified) example of a car customizer (we take Car as a resource that is customized and to be shared)

  1. A User creates a new resource (e.g., a Car) and starts adapting it. Thereby, several properties of Car are changed during run time (e.g., the color, engine, ...) and stored in the database.
  2. The user can then generate a shortcode (i.e., a shareable-link) to the model (Car) that he created in order to send it to friends, or continue configuring it another day.

Specific questions here are:

  1. What would be your "go to" strategy in order to generate exactly one shareable_link for the Car model (e.g., I dont want to have multiple links "pointing" to the same model). Probably the link should be created when creating the Car model.
  2. How can you directly "show" the link to the user that he is able to send the link via e-mail to his friends. How would you "represent" this in the database and model-layer? You would need to have an additional sharelink_id field in the cars table (and Car model respectively). And (as described in 1) automatically link them when creating the Car? Or is there another way of "navigating back" (from Car to the ShareLink?)

Thank you for your time & help,
Best,
Johannes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.