質問

To stay basic I would like to create a bookmark app

I have a simple bookmarklet

javascript:location.href='http://zas.dev/add?url='+encodeURIComponent(location.href)

I created a rest controller

<?php

use zas\Repositories\DbLinkRepository;

class LinksController extends BaseController {

protected $link;

function __construct(DbLinkRepository $link) {

        $this->link=$link;
        // ...
        //$this->beforeFilter('auth.basic', array('except' => array('index', 'show', 'store')));
        // ...
}


public function index()
{
    //return Redirect::to('home');
}
public function create()
{

}
public function store()
{
    return 'hello';
    //$this->link->addLink(Input::get('url'));
    //return Redirect::to(Input::get('url'));
}
public function show($id)
{
    //$url = $this->link->getUrl($id);
    //return Redirect::to($url);
}
public function edit($id)
{

}
public function update($id){

}
public function destroy($id){

}
}

in the routes.php, I created a ressource

Route::resource('links','LinksController');

and as I want to redirect /add to the store method I added

Route::get('/add',function(){
    return Redirect::action('LinksController@store');
});

but it never display the hello message, in place it redirects me to

http://zas.dev/links

I also tried with

return Redirect::route('links.store');

without much success

thanks for your help

役に立ちましたか?

解決

Ok I now get what you are trying to do. This will work:

Route::get('add', 'LinksController@store');

Remove:

Route::resource('links','LinksController');

and remove:

Route::get('/add',function(){
   return Redirect::action('LinksController@store');
});

Sorry it took so long!

他のヒント

The problem is that once you Redirect::, you loose all the Input values, so you should manually give them to your controller when you do the redirect, like so :

Redirect::route('links.store', ["url" => Input::get("url")]);

Finally add an $url parameter to your store method to receive the value we give it in the previous method, like this :

public function store($url) {
    $this->link->addLink($url);
    return Redirect::to($url);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top