laravel-4

Laravel sort Relationship

自古美人都是妖i 提交于 2019-12-21 04:58:30
问题 How can I sort my result with related tables? I have this tables: Clients and Managers (users table) Client.php <?php class Client extends Eloquent { protected $table = 'clients'; public function Manager(){ return $this->belongsTo('User','manager','id'); } public function Transaction(){ return $this->hasMany('ClientTransaction','client','id'); } } Users.php (default Laravel's model) My question is how can I query table clients to be sorted by Manager's name. Here is my code so far: public

What is the value of using PUT/DELETE with Laravel?

你。 提交于 2019-12-21 04:54:07
问题 For defining a route as a resource with Route::resource , the docs indicate: Verb Path Action Route Name ------------------------------------------------------------------- GET /resource index resource.index GET /resource/create create resource.create POST /resource store resource.store GET /resource/{resource} show resource.show GET /resource/{resource}/edit edit resource.edit PUT/PATCH /resource/{resource} update resource.update DELETE /resource/{resource} destroy resource.destroy as per

How to simulate xmlHttpRequests in a laravel testcase?

怎甘沉沦 提交于 2019-12-21 04:49:13
问题 Updates see below My controllers distinguish between ajax and other requests (using Request::ajax() as a condition). That works quite fine but I wonder if there is a way of unit testing the controllers handling the the requests. How should a test look like? Something like this probably but it doesn't work ... <?php class UsersControllerTest extends TestCase { public function testShowUser() { $userId = 1; $response = $this->call('GET', '/users/2/routes', array(), array(), array( 'HTTP_CUSTOM'

Laravel 4 Pagination bug with Twitter Bootstrap 3

ⅰ亾dé卋堺 提交于 2019-12-21 04:27:08
问题 When using Laravel Pagination, I believe that the css classes generated are relevant to bootstrap 2 and not bootstrap 3. {{ $products->links() }} generates <div class="pagination"> <ul> <?php echo $presenter->render(); ?> </ul> </div> However I would like it to generate: <ul class="pagination"> <?php echo $presenter->render(); ?> </ul> Without changing the framework code laravel/framework/src/illuminate/pagination/views/slider.php , is there a better / proper way of overriding the CSS / code

Laravel 4 cannot run whole RAW queries

随声附和 提交于 2019-12-21 04:07:19
问题 I would like to use the DB class of laravel to execute a mysql query but none of the functions provided by Laravel are working. None of those is working: DB::statment() / DB::select() / DB::raw() / DB::update() / DB::select(DB::raw()) Here is the code I would like to query: DROP TABLE users; CREATE TABLE `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `u_username` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `u_email` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `password`

Laravel Class 'App\Modules\ServiceProvider' not found?

僤鯓⒐⒋嵵緔 提交于 2019-12-21 03:47:12
问题 Hello Friends I am new in Laravel framework. i create modules directory in app folder. then i also create ServiceProvider.php file in modules directory. my file structure like. app\modules\ServiceProvider.php This is code of ServiceProvider.php. <?php namespace App\Modules; abstract class ServiceProvider extends \Illuminate\Support\ServiceProvider { public function boot() { if ($module = $this->getModule(func_get_args())) { $this->package("app/" . $module, $module, app_path() . "/modules/" .

Laravel Delete Query Builder

戏子无情 提交于 2019-12-21 03:26:12
问题 In Laravel 4 Illuminate\Database\Query in a Builder class delete function accepts null as an id parameter. And behaivor of this function implies that if I have something like: DB::table('users')->where('id', $id)->delete(); And if $id will be passed as a null , it will truncate the whole table. Which means that besides standard validation, I have to wrap every delete statement with ! is_null($id) validation. Is it a security breach or it's considered as a standard practice? 回答1: I think you

Where do I put Laravel 4 helper functions that can display flash messages?

走远了吗. 提交于 2019-12-21 03:18:24
问题 I've written a simple display_messages() function that will search Session::get('errors') for flash data and echo it to the screen. Where do I put this function? In Codeigniter, you had a helpers folder where you could stick all your little global helper methods. 回答1: As Usman suggested, create a file /application/libraries/demo.php define a class Demo() { inside it call the function like so: {{ Demo::display() }} Works because libraries and models are autoloaded in start.php line 76. I

Laravel 4: how to update multiple fields in an Eloquent model?

徘徊边缘 提交于 2019-12-21 03:12:32
问题 How can I update multiple fields in an Eloquent model? Let's say I got it like this: $user = User::where("username", "=", "rok"); And then I have all these model parameters: $new_user_data = array("email" => "rok@rok.com", "is_superuser" => 1, ...); I can't just do: $user->update($new_user_data); What's the proper way? I hope not a foreach . The following does work, however. Is this the way to go? User::where("id", "=", $user->id)->update($new_user_data); The problem with the last one

How to filter a pivot table using Eloquent?

女生的网名这么多〃 提交于 2019-12-21 03:10:50
问题 I'm using a pivot table on the project I'm working with to get works of users. E.g: User::find(1)->works gives me the works of user with ID of 1. The thing is that I want to filter this results with extra Pivot data. Something like: User::find(1)->works->pivot->where('active',1)->get(); In which the active is the column I've set in my user_works pivot table. This is my related part of my User.php model: <?php class User extends Cartalyst\Sentry\Users\Eloquent\User { public function works() {