laravel-4

Laravel 4 : Route to localhost/controller/action

柔情痞子 提交于 2019-12-17 12:41:53
问题 I'm more or less new to Laravel 4. I've never used routes before but normally what I'm used to is url/controller/action and then the backend routing for me. I've read the documentation for routes and controllers a few times as well as read through some tutorials and so, I'm trying to figure out how to get this to work without writing a route for every controller and action. I tried something like Route::get('{controller}/{action}', function($controller, $action = 'index'){ return $controller.

Laravel 4 : Route to localhost/controller/action

♀尐吖头ヾ 提交于 2019-12-17 12:41:05
问题 I'm more or less new to Laravel 4. I've never used routes before but normally what I'm used to is url/controller/action and then the backend routing for me. I've read the documentation for routes and controllers a few times as well as read through some tutorials and so, I'm trying to figure out how to get this to work without writing a route for every controller and action. I tried something like Route::get('{controller}/{action}', function($controller, $action = 'index'){ return $controller.

Laravel Queries Strings

99封情书 提交于 2019-12-17 11:42:24
问题 Does anyone know if it's possible to make use of URL query's within Laravel. Example I have the following route: Route::get('/text', 'TextController@index'); And the text on that page is based on the following url query: http://example.com/text?color={COLOR} How would I approach this within Laravel? 回答1: Yes, it is possible. Try this: Route::get('test', function(){ return "<h1>" . Input::get("color") . "</h1>"; }); and call it by going to http://example.com/test?color=red . You can, of course

Laravel 4, Pass a variable to route in javascript

*爱你&永不变心* 提交于 2019-12-17 10:54:27
问题 How Can I pass the variable (stock.id) return from Ajax response to the route to generate the url to edit a stock $.ajax({ url: 'sectors/stocks/' + $(this).data('sector-id'), dataType:'json', beforeSend:function() { $('.stocks_list').html('Loading...'); } }) .done(function(data) { $('.stocks_list').html('<ul>'); $.each(data, function(index, obj_data) { $.each(obj_data.stocks, function(indx, stock) { $('.stocks_list').append('<li><a href="{{route("admin.stocks.edit","'+stock.id+'")}}">' +

How to send data with angularjs $http.delete() request?

青春壹個敷衍的年華 提交于 2019-12-17 10:47:52
问题 I have a resource 'roles' which has a many to many relationship with 'user'. To administer 'roles' I need to send the role id and the user id to the server so that it removes the the role from the correct user (not necessarily the logged in user) Here is what I was attempting but according to the docs this is not possible. I know I can send the two ids in the uri but my laravel backend automatically sets up a resourceful route of resource/{resourceid} which I would like to use if possible. Is

'Malformed UTF-8 characters, possibly incorrectly encoded' in Laravel

眉间皱痕 提交于 2019-12-17 10:47:38
问题 I'm using Laravel (a PHP framework) to write a service for mobile and have the data returned in JSON format. In the data result there are some fields encoded in UTF-8 . The following statement return JsonResponse::create($data); returns the error below InvalidArgumentException HELP Malformed UTF-8 characters, possibly incorrectly encoded Open: /var/www/html/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/JsonResponse.php } catch (\Exception $exception) { restore_error_handler(

Laravel Eloquent “WHERE NOT IN”

房东的猫 提交于 2019-12-17 10:44:39
问题 I'm having trouble to write query in laravel eloquent ORM . my query is SELECT book_name,dt_of_pub,pub_lang,no_page,book_price FROM book_mast WHERE book_price NOT IN (100,200); Now I want to convert this query into laravel eloquent. 回答1: Query Builder: DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get(); Eloquent: SomeModel::select(..)->whereNotIn('book_price', [100,200])->get(); 回答2: You can use WhereNotIn in following way also: ModelName::whereNotIn('book_price', [100,200]

First Or Create

自作多情 提交于 2019-12-17 10:32:10
问题 I know using: User::firstOrCreate(array('name' => $input['name'], 'email' => $input['email'], 'password' => $input['password'])); Checks whether the user exists first, if not it creates it, but how does it check? Does it check on all the params provided or is there a way to specifiy a specific param, e.g. can I just check that the email address exists, and not the name - as two users may have the same name but their email address needs to be unique. 回答1: firstOrCreate() checks for all the

How to create a database-driven multi-level navigation menu using Laravel

拜拜、爱过 提交于 2019-12-17 10:29:30
问题 I'm new to Laravel 4 and I'm totally confused about it's models. I'm trying to create a database-driven navigation menu for my project and all I know is I have to create a model to interact with the database (based on my knowledge from codeigniter). I have been studying alot and I'm tired of not being able to go forward, this is the code I have come up with till now: /app/models/navigation.php <?php class Navigation extends Eloquent { /** * The database table used by the model. * * @var

Running one specific Laravel migration (single file)

隐身守侯 提交于 2019-12-17 10:25:43
问题 I don't want to run All Outstanding Migrations on laravel 4. I have 5 migrations. Now I just want to run one migration. instead of doing : php artisan migrate I would like to run one specific migration like : php artisan migrate MY_MIGRATION_TO_RUN 回答1: Looks like you're doing it wrong. Migrations were made to be executed by Laravel one by one, in the exact order they were created , so it can keep track of execution and order of execution. That way Laravel will be able to SAFELY rollback a