laravel-4

Accessing nested relationship with Laravel 4

若如初见. 提交于 2019-12-23 15:24:50
问题 I'm having trouble figuring out how to access a nested relationship within Laravel. The specific example I have is a Movie that has many entires in my Cast table which has one entry in my People table. These are my models: MOVIE class Movie extends Eloquent { protected $primaryKey = 'movie_id'; protected $table = 'movie'; // Relationships public function cast() { return $this->hasMany('MovieCast', 'movie_id'); } } MOVIECAST class MovieCast extends Eloquent { protected $table = 'movie_cast';

how to implement multiauth in laravel passport

天涯浪子 提交于 2019-12-23 12:51:24
问题 I have two users admin/user i want to authenticate this two users for api, it is working for one user but its not working for admin see what i have tried in admin controller public function login(Request $request){ // $res=; // dd ($res); if(Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password])) { // if successful, then redirect to their intended location $user = auth()->guard('admin')->user(); $success['token'] = $user->createToken('admin')-

Laravel 4: avoid duplicate entry

梦想与她 提交于 2019-12-23 12:29:19
问题 In my app there is a simple form with one field (email) that give the possibility to register to the newsletter. If i entry a new email, all it works fine. If i entry an email that already exists in the database i get the error SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry... Because i had defined that field as unique in the database. All i want to do is to redirect::back()->with('message', 'email already registered') But i do not know how can i do this? I can just put

Laravel 4 remove /index on default getIndex controller function

心已入冬 提交于 2019-12-23 12:16:54
问题 Is it possible to remove /index on default getIndex restful controller function? Defined route for controller: Route::controller('registration', 'RegisterController', array( 'getIndex' => 'getRegister' )); Controller: class RegisterController extends UserController { public function getIndex() { // Show the register page return View::make('register'); } } For example, in my login.blade.php i have: {{ HTML::link(URL::route('getRegister'), 'New User?', array('title' => 'Novi korisnik?', 'class'

How to set sub-directory for base URL of laravel?

被刻印的时光 ゝ 提交于 2019-12-23 11:39:08
问题 Normally laravel will detect the base url automatically. However, this is not possible when the function is called by command line in console. Therefore, under path_to_laravel_folder/public/config/app.php , there is a variable named url , which according to the official comment, should be the base url when laravel is called in command line. Currently I have a daily task to be run on laravel and therefore is called by command line. In the app.php, I have set the url variable to be: 'url' =>

Should I include underscore in session cookie name?

最后都变了- 提交于 2019-12-23 11:00:34
问题 I'm curious if there is anyone using Laravel since version 3 running into problems setting cookies in various version of IE when there is an underscore in the cookie name. I came across this problem with my project (an eCommerce site built on CI). The problem was fixed removing the underscore in cookie name. While I'm currently porting the project to Laravel, I just want to check if I should remove the underscore from session cookie as well. 回答1: I would definitely recommend removing any

how to make query with substr in eloquent (laravel 4)?

末鹿安然 提交于 2019-12-23 09:49:18
问题 I have this query: select substr(id,1,4) as id from meteo.a2012 group by substr(id,1,4) I just want to take first 4 numbers to my id row, but I'm trying to do in eloquent, how I do? Thanks. 回答1: You need to use raw expressions so you can use special functions like that. Model::select(DB::raw('substr(id, 1, 4) as id'))->groupBy(DB::raw('substr(id, 1, 4)'))->get(); Where Model is your Eloquent model you want to run the query on. 回答2: $ids = Model::get(['id']); foreach ($ids as $str) { $str->id

Different name fields user table?

老子叫甜甜 提交于 2019-12-23 09:25:26
问题 I have a form with 2 fields ( username, password ) and a mysql table with those 2 same fields (username, password), and I authentication system working properly :) But, I can not make it work if my table fields have different names, for example: ( my_user, my_pass ). If you just change the username field on the other also works for me, that gives me problems is the password field. My config auth.php 'driver' => 'eloquent' Update Already found the solution in my controller, the password name

Convert date and time to Jalali in Laravel

孤街醉人 提交于 2019-12-23 08:50:07
问题 I want to change the time and date calendar to Jalali (Shamsi calendar used in Iran) in my system. How can I do this? "language_title" => "English", "dir" => "ltr", // ltr = left to right, rtl = right to left "language_code" => "en", "intl_locale" => "en_US", "dec_point" => ".", "thousands_sep" => ",", "dateformat_full" => "D, M j Y g:i A", // http://php.net/manual/en/function.date.php "dateformat_date_long" => "D, M j Y", // http://php.net/manual/en/function.date.php "intl_dateformat_full" =

Loading a laravel view with .html extension

半城伤御伤魂 提交于 2019-12-23 08:28:48
问题 Is it possible to have Laravel load view templates with a .html extension? I'm rebuilding an existing app that has a bunch of .html files that are uploaded by users. It's a sort of multi-tenant application where each user can control the look and feel of their area by uploading templates. I need to rebuild the app and make the change completely transparent to the users so I'd like to keep the .html extensions. 回答1: The best way I have found is to use View::addExtension in your base controller