laravel-4

Many-to-Many Eloquent relationship update with Laravel Form Model Binding & Checkboxes

亡梦爱人 提交于 2019-12-04 17:11:37
问题 I have 3 tables: doors id name image colors id name image door_colors id door_id color_id and 2 models with a many-to-many relationship (each door comes in a variety colors, and many colors overlap door-to-door): Door Model class Door extends Eloquent { public function colors() { return $this->belongsToMany('Color', 'door_colors'); } } Color Model class Color extends Eloquent { public function doors() { return $this->belongsToMany('Door', 'door_colors'); } } I want to create a form where I

Save .JSON file to database using laravel

ぐ巨炮叔叔 提交于 2019-12-04 17:11:07
I am very new to Laravel and PHP in general, most of what I have worked on has been relative to online tutorials. I know how to save single items like a username or password to my database but I am clueless when it comes to storing an entire file.This is how my database is currently formatted in my migration file: public function up() { Schema::create('users', function(Blueprint $table) { $table->increments('id'); $table->string('username'); $table->string('email')->unique(); $table->string('password', 60); $table->string('remember_token')->nullable(); $table->timestamps(); }); } Any help is

Laravel 5.1: How to limit account access so one account can be accessed at one time

你说的曾经没有我的故事 提交于 2019-12-04 16:47:29
I am relatively new to Laravel, but I would like to restrict account access so that only one account can be logged into at one time. For example, if I were to log into my account on my work computer and then I logged in at my home computer simultaneously, it would not log me in and prompt me to logout of the first computer. What is the best and correct way of doing this? Many Thanks This is more a 'logic' question than one about Laravel. In short I would build something like this; Add a field to the user table like 'active_at' with a timestamp in it and a 'active_device' with a unique value

Call to undefined method Illuminate\Database\Query\Builder::save()

做~自己de王妃 提交于 2019-12-04 16:45:34
问题 I am trying to call Eloquent's save() method on an existing record but getting an error from Illuminate's Query Builder. Following the documentation on Laravel's web site at http://laravel.com/docs/eloquent#insert-update-delete for updating a retrieved model, and also looking at the example here: Laravel Eloquent ORM save: update vs create, my code appears to follow the expected convention, but instead I get the error mentioned in the title of this post. $this->employee = Employee::where(

Laravel multi-tenant approach. Where to start

三世轮回 提交于 2019-12-04 16:42:25
I've a full application coded. Now, the only part missing is to make it multi-tenancy. I want to allow clients to register into my application website and get an instance of the application with a completely empty database only for that account. I've thought to play with environments, but I'm not sure if this is a good approach: config - user1 - database.php - user2 - database.php - ... I've also thought about a unique config file containing the database information about every account and set the database connection based on the subdomain name. Something like I've seen in this post: Multi

Laravel 4.1 remove pivot attributes from response

Deadly 提交于 2019-12-04 16:28:04
问题 I am using laravel 4.1 to build an api. I have pivot a table which is working fine. But the response comes with pivot attributes which i don't want. as you will see in my example i have to two tables name: trips and users. I don't want to see pivot table attributes in my response. Here is the example: [ { "id": 140, "name_first": "hasan", "name_last": "hasibul", "profile_image": "/assets/images/default-profile-img.png", "created_at": "2013-09-18 08:19:50", "last_login": "2013-12-26 11:28:44",

composer | laravel 5 - Updating dependencies but the framework itself

大兔子大兔子 提交于 2019-12-04 16:07:13
I am using pre-beta release of Laravel 5 for my project. I found out that the app skeleton of Laravel 5 was changed in the github repo and since it is a development version, that is expected to change quite frequently. My question is, can I update only the specific dependencies using composer and not the framework itself? So that I don't have to worry about the changing app structure until I am ready to make changes? Here is how the composer.json dependencies look: "require": { "laravel/framework": "~5.0" }, "require-dev": { "phpunit/phpunit": "~4.0", "way/generators": "~3.0", "fzaninotto

Extend Blueprint class?

陌路散爱 提交于 2019-12-04 15:59:17
问题 I want to override the timestamps() function found in the Blueprint class. How can I do that? e.g., public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('username')->unique(); $table->string('password'); $table->string('email'); $table->string('name'); $table->timestamps(); // <-- I want this to call my method instead of the one found in the base Blueprint class }); } 回答1: There is a new blueprintResolver function which takes a

Behat 3 and Laravel, testing environment not being honoured

本小妞迷上赌 提交于 2019-12-04 15:50:42
I am having a confusing problem using Behat 3 and Laravel to test an API. It seems that its not using the 'testing' environment database (in my case an sqlite memory database) ... but only some of the time. I've put a log message in the testing/database.php file to see when its loaded.. and I do see the log message when running Behat. But running the Behat features is adding rows to my development database - and some of my tests are failing for the same reason. My phpunit tests run fine and do not alter the dev database. Is there something that should be in behat.yml that I've missed? EDIT: I

Server-sent events inside Laravel

旧城冷巷雨未停 提交于 2019-12-04 15:02:39
I am trying to implement the HTML5 Server-sent events inside Laravel 4, I found this repo the script uses server.php file to get it working. My question is how would I implement it to get it working with a Controller instead of a plain php file? So in the Javascript side it will look like this: var source = EventSource('/notifications'); I tried this just to see if I get a response: class NotificationsController extends BaseController { public function index() { $response = Response::view('notifications.index'); $response->header('Content-Type', 'text/event-stream'); $response->header('Cache