laravel-4

laravel 4 install issue when using composer install

China☆狼群 提交于 2019-12-11 01:36:11
问题 When I run composer.phar install I get this error almost at the end of the installation, any ideas? Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Nothing to install or update Generating autoload files Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/belendez/public_html/laravel/artisan on line 46 Parse error: syntax error, unexpected T_STRING in /home/belendez/public_html/laravel/artisan on line 46

How to use Eager Loading and Join in Eloquent at a same time in laravel 4

痴心易碎 提交于 2019-12-11 01:09:30
问题 Models class WPModel extends Eloquent { protected $table = 'work_processes'; protected $guarded = array('id'); protected $softDelete = true; // declaring one-to-many relationship public function relatedWPAQs() { return $this->hasMany('WPAQModel', 'wp_id'); } public function relatedUsers() { return $this->belongsTo('UserModel', 'wp_owner_id'); } } class UserModel extends Eloquent { protected $table = 'users'; protected $softDelete = true; public function relatedWPs() { return $this->hasMany(

Creating Wordpress like shortcode in laravel blade

不羁的心 提交于 2019-12-11 00:25:37
问题 I have a mail template (in laravel blade) that is need to be dynamic (so it should be saved in database i think). This is the registration_complete.blade.php: <html> <body> {{$dynamic_content_from_database}} </body> </html> And the $dynamic_content_from_database value came from the WYSIWYG i used.This is the management i worked for : I need to find a way that admin user can manage the content of the template with variable inside or shortcode. Just like in WordPress they used short code to put

Join to display spesific data in query builder laravel

▼魔方 西西 提交于 2019-12-11 00:14:39
问题 Let's say I have 2 table in database In laravel I used query builder like this DB::table('chart')->join('chart_detail', 'chart.id', '=', 'chart_detail.id_cart')->get(); The result is something like this: It's not what I want to display data, because too much redundancy I want to display data like this: Where I'm wrong in join sql command? 回答1: This is not something you can do with your query exactly... on your front-end you can group it together by doing something like this (better to use a

How to remove coupon from Stripe plan w/ Laravel Cashier 4

狂风中的少年 提交于 2019-12-10 23:43:08
问题 I am currently trying to implement a method that swaps people over to a new plan. The problem I am having is that the coupon from the old plan carries over and the user is not charged. Every time I try to remove the old coupon, it doesn't seem to allow it. protected function swapToYearlyPlan(){ $user = Auth::user(); // Tried this, doesn't work // $user->subscription()->retrieve($user->stripe_subscription)->deleteDiscount(); // This works fine $user->subscription('Gold Annual Plan')->swap(); /

Laravel 4 - Return user id on save()

非 Y 不嫁゛ 提交于 2019-12-10 22:46:31
问题 Im wondering if someone can help me out. I need to create a record in my database when a user signs up which needs the users newly created ID. I have my standard code to insert a user as follows. $user = new User; $user->email = Input::get('email'); $user->save(); So i need the ID of the saved user. Is that possible? Cheers 回答1: I'm pretty sure you can just call the ID afterwards as it is populated by Eloquent: $user = new User; $user->email = Input::get('email'); $user->save(); echo $user-

Laravel 4 - Access Auth Class in Validation Class

我是研究僧i 提交于 2019-12-10 22:34:11
问题 I want to access the Auth Class within my ValidatorService Class. namespace Services\Validators\User; use \Services\Validators\Validator; use \Illuminate\Support\Facades\Auth; class Edit extends Validator { public static $rules = [ 'email' => 'required|unique:users,email,'.Auth::user()->id ]; } I tried to use the \Illuminate\Support\Facades\Auth Namespace, but laravel throws an Exception. Error: syntax error, unexpected '.', expecting ']' Laravel only throws the exception, when I try to use

Laravel 4 - JOIN - Same column name

一世执手 提交于 2019-12-10 22:20:04
问题 I do currently use this code to retrieve the required data from my database $query = DB::table('packages') ->join('assigned_packages', function($join) use($id) { $join->on('packages.id', '=', 'assigned_packages.registered_package_id') ->where('assigned_packages.customer_id', '=', $id); }) ->join('registered_packages', function($join) { $join->on('packages.id', '=', 'registered_packages.id') ->on('registered_packages.id', '=', 'assigned_packages.registered_package_id'); }); It works fine,

LARAVEL get result of withErrors in view

岁酱吖の 提交于 2019-12-10 22:03:44
问题 in controller i'm using: if ($validator->fails()) { return Redirect::to('/admin/profile') ->withErrors($validator) ->withInput(); } how to get result of withErrors in view ? {{ $errors->all() }} 回答1: If you want to show all errors in one place you can use @foreach ($errors->all() as $error) <div>{{ $error }}</div> @endforeach If you want to show each field's errors e.g. bellow the field you can use (e.g. for email) {{ $errors->first('email') }} we use first() in order to show only one error

Laravel order by conditions eloquent or sql

与世无争的帅哥 提交于 2019-12-10 21:42:53
问题 I have these timestamp columns in database table - expiration, edit, created_at. I need to order by 'edit', if item 'expiration' date is bigger than today's date, else I need to order by 'created_at'. I am trying something like this, but it isn't working correctly $items = $items ->orderBy(DB::raw("CASE WHEN expiration >= $time THEN edit ELSE created_at END"), 'DESC') ->get(); or $items = $items ->orderBy(DB::raw("CASE WHEN expiration >= $time THEN edit END"), 'DESC') ->orderBy('created_at',