laravel-4

Extra information table joined without eloquent model

非 Y 不嫁゛ 提交于 2019-12-12 02:11:34
问题 Say I have an database table called Item (with a name and a type). Now depending on the type, the item has extra information: e.g. if it is a ScoredItem it has a Score. So I created a database table ItemScore, which assigns a score to an item. I then have an eloquent model: Item (with the name and the type), but how should I go about adding this Score property. An obvious solution would be to create a model: ItemScore and set the correct relation (using hasMany and belongsTo). But because it

Laravel: get/show data from related tables

廉价感情. 提交于 2019-12-12 02:00:45
问题 I have two related tables like this: publishers | id | name | |----|----------| | 1 | EA Games | | 2 | Nintendo | games | id | publisher_id | title | |----|--------------|-------------| | 1 | 1 | FIFA 2014 | | 2 | 2 | Super Mario | | 3 | 1 | The Sims | My index page is built like this: public function index(){ $games = Game::all(); return View::make('/games/index', compact('games')); } And of course my Blade template is like this: <table class="table table-striped"> <thead> <tr> <th>Title</th

Laravel - Repopulate checkbox to ticked or unticked

元气小坏坏 提交于 2019-12-12 01:59:28
问题 In Laravel, if validation failed, it goes back to a same form page. How to repopulate a checkbox to ticked or unticked? By default, it should be unticked when loading on the page for the first time. {{ Form::checkbox('custom_address', false, Input::old('custom_address'), array('class' => 'test')); }} 回答1: You need to set a value for your checkbox, otherwise the Input class will always have it empty / unchecked. Give the checkbox a value of 1, then it should work. {{ Form::checkbox('custom

Laravel 4 Route Parameters for REST

匆匆过客 提交于 2019-12-12 01:58:15
问题 This might be a simple problem but I'm on testing with Laravel. I set my routes like this accordingly: // Users Route Route::get('users',array('as'=> 'users', 'uses'=> 'UsersController@index')); Route::get('users/{id}', array('as' => 'user', 'uses' => 'UsersController@show') ); Route::get('users/{id}/edit', array('as' => 'edit_user', 'uses' => 'UsersController@edit') ); Route::get('users/new', array('as' => 'new_user', 'uses' => 'UsersController@create')); Route::post('users',

laravel how to route to another function in the same controller

你。 提交于 2019-12-12 01:57:25
问题 I have a controller for registering, when the user register successfully I would like to route him to his profile page. In user controller I have these functions: save show($id) when registering, the user fires the save function. so my question is how to route him to the show function with the id ? I could make view:make() but I don't want to route him directly to the view but first I want to route him to the show function to do some stuff and then in the show function I do view.make 回答1: you

Call to a member function whereHas() on a non-object in laravel

点点圈 提交于 2019-12-12 01:56:23
问题 In my controller I have wrote this following code $usersCount = User::where('activated', '=', 1)->where('group_id', '=', 1)->where('availability_date', '<=', $opportunity_date)->count(); $locations_array_result = explode(",",$locations_array_result); foreach ($locations_array_result as $param) { $usersCount = $usersCount->whereHas('location', function($q) use($param){ $q->where('location_id', '=', $param ); }); } This code giving following error Call to a member function whereHas() on a non

One to many relationship count - difference in accessing relationship

流过昼夜 提交于 2019-12-12 01:55:37
问题 I have one to many relation - Entry can have many Visits . In my Entry model I have the following methods: public function visits() { return $this->hasMany ('Visit', 'entry_id','id'); } public function visitsCount() { return $this->hasMany('Visit', 'entry_id','id') ->selectRaw('SUM(number) as count') ->groupBy('entry_id'); } In Blade I can get number of visits for my entry using: {{$entry->visits()->count() }} or {{ $entry->visitsCount()->first()->count }} If I want to create accessor for

Laravel: Undefined variable

家住魔仙堡 提交于 2019-12-12 01:53:34
问题 im having a problem with my code. I want to show the record of the student who login but im having an undefined variable on my view.blade Here's my Model class Attendance extends Eloquent { public function users() { return $this->belongsTo('User', 'id'); } } Here's my Controller public function viewstudentAttendance() { $students = Auth::user()->id; //load view and pass users return View::make('student.view') ->with('attendances', $students); } Finally here's my view.blade @extends('layouts

Failed to load resource: the server responded with a status of 404 (Not Found)

左心房为你撑大大i 提交于 2019-12-12 01:53:32
问题 http://localhost:8080/asset/js/boostrap.min.js Failed to load resource: the server responded with a status of 404 (Not Found) In my folder asset/js/ I´ve the file boostrap.min.js What´s the problem? 回答1: There are many reasons you get a file not found exception. The most popular is the file permissions. If you are on UNIX try chmod -R 777 in the folder that contains bootstrap.min.js. If this doesn't works you have to review the server conf files or the .htaccess files. If you want a "just

Laravel: Extending an installed Bundle's User Model

让人想犯罪 __ 提交于 2019-12-12 01:44:44
问题 I've installed the Sentinel laravel bundle into my project. I've published the packages views and added several fields to the registration form. I wanted those fields to write to my users database table. I found the store() method of the SentryUser class in the SentryUser.php file within the bundle's directories and saw the line: $user = $this->sentry->register(array('email' => e($data['email']), 'password' => e($data['password']))); I modified this mapping to include one of my additional