laravel-4

Creating the database on fly

让人想犯罪 __ 提交于 2019-12-04 19:07:30
I am working on laravel 4 app, In that i wan to allow the user to register for the app and when they register the app should allow a new empty database to the registered user,I am using mysql for backend I know the following code to set the database connection Config::set('database.connections', ConnectionArray); And to set it as default Config::set('database.default', ConnectionKey); To connect another database manually i can use this way 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '123456', 'charset' => 'utf8',

Call shell commands from laravel controller?

微笑、不失礼 提交于 2019-12-04 18:56:32
问题 Is it possible to call Shell commands (e.g for converting images ) from laravel controller? If yes then how. I have searched on internet. Nothing seems relevant. Please Guide. Thanks 回答1: You can use the Process component provided by Symfony: http://symfony.com/doc/current/components/process.html The component is used by Laravel itself, so it can be loaded directly. If you use it(instead of php's exec() function), you'll be able to unit test the code that calls shell commands. 回答2: It all

Laravel - Send Variable to layout master and keep it during session

人走茶凉 提交于 2019-12-04 18:54:14
I am wondering if there are any way in laravel to send a variable to the layout master and keep it there while the user is logged in. I know how I can do it, like this $this->layout->with('catalog.categories', $data); But the problem of this is that I will have to be sending the variable on all the controllers and through all the class. And to get the variable I will need seven or eight lines of code on top of that. I will give you an easy example. Imagine I have a messenger center in my web. And I want to show the user all the messages he did not read on the top bar. It has to be on the

Artisan output buffer does not contain all output

可紊 提交于 2019-12-04 18:44:52
I'm using the following code to redirect the output of an artisan command within a route. use Symfony\Component\Console\Output\BufferedOutput; Route::get('/restart', function() { $output = new BufferedOutput; Artisan::call('remote:restart', array(), $output); return $output->fetch(); }); This works for most cases. However if within the command I use the SSH component to run some tasks on a remote server, the output resulting from SSH::into()->run() will be disregarded by the above code. If I run the artisan command manually, I get the following output: start [root@remote-host] (xxxx) Stopping

How to insert an object (Model type object) into Collection Object in Laravel at specific index number?

喜夏-厌秋 提交于 2019-12-04 17:51:30
问题 I have read Dayle Rees's Code Bright to know more about Eloquent Collection s used in Laravel. Did some other research as well but couldn't find the answer I was looking for. I want to insert an object ( Model type object) into a Collection Object at a specific position. For example: This is the returned collection Illuminate\Database\Eloquent\Collection Object ( [0] => Attendance Object ([present_day] => 1) [1] => Attendance Object ([present_day] => 2) [2] => Attendance Object ([present_day]

How can I update an existing Eloquent relationship in Laravel 4?

故事扮演 提交于 2019-12-04 17:41:53
问题 I am trying to update the relationship of a one-to-many relationship in Laravel. Unfortunately I couldn't find any documentation for it. Can anyone help me? This is what I have so far: class Account extends Eloquent { public function users() { return $this->hasMany('User'); } } class User extends Eloquent { public function account() { return $this->belongsTo('Account'); } } Now I am trying to update the relationship from USER(1) > ACCOUNT(50) to USER(1) > ACCOUNT(99). How would I do this? I

Returning multiple Laravel Eloquent models as JSON

一个人想着一个人 提交于 2019-12-04 17:26:28
My "user" model with a has-many relationship to an "image" model. Returning just the user is as easy as "return Response::eloquent($user);". I'd like to either return a JSON array of {user: {id:…}, images: [{id:…},{id:…}]} or, perhaps better, {id:…, images: [{id:…},{id:…}]} What's the best way to arrange and ship these models? Should I The first thing you'll need to do is make sure your models are set up correctly: class Users extends Eloquent { public function images() { return $this->hasMany('Image'); } } class Image extends Eloquent { public function user() { return $this->belongsTo('User')

How do you wrap Laravel Eloquent ORM query scopes in parentheses when chaining?

流过昼夜 提交于 2019-12-04 17:21:06
问题 In Eloquent, I'd like to generate this query: SELECT * FROM table WHERE a=1 AND ( b=2 OR c=3 ); But I seem to be generating this query instead: SELECT * FROM table WHERE a=1 AND b=2 OR c=3; Here is my implementation and code: $result = Model::aIsOne()->bIsTwoOrCIsThree()->get(); Model contains: function scopeAIsOne($query) { return $query->where('a', 1); } function scopeBIsTwoOrCIsThree($query) { return $query->where('b', 2)->orWhere('c', 3); } Thanks for any help. I've searched through the

Extract words from an Image and PDF - Laravel [closed]

北慕城南 提交于 2019-12-04 17:16:45
is there any way to extract words from scanned images and PDF? Is there any such library for Laravel as I want to use it for laravel. I have searched a lot for that but did not found any such thing for Laravel. Please let me know if you are aware about it. Every help would be highly appreciated :-). Thanks to all of you in advance !!!! joshuamabina After doing some reading... Its possible to read text from scanned images and PDF. I too couldn't find libraries for image processing built for explicit use with laravel, but I did find PHP wrappers for the infamous OpenCV and TesseractOCR , maybe

Typeahead remote with Laravel 4 - Individual pieces working I think, but not working together

自作多情 提交于 2019-12-04 17:16:06
I'm relatively green with Laravel and PHP. I'm learning Laravel by way of the documentation and SO/Google. I've clicked on every typeahead/laravel question I could find here, and I just can't seem to find an example that quite fits. This question comes very close. I actually don't see any glaring differences. But then again, that OP was having trouble with remote as well. I think I'm close, as my various pieces seem to be working individually. Let me explain... I have a form... <div class="input-group form-group" id="ingredients"> {{ Form::label('ingredients', 'Ingredients') }} {{ Form::text(