laravel-5

Laravel 5 relationship using a 'JSON' column

僤鯓⒐⒋嵵緔 提交于 2021-01-29 09:13:34
问题 Is it possible to use Eloquent to create a relationship in Laravel 5 where the foreign key exists in a field in a JSON column? If it is, how so? Example: I have a table called chats with a participantIds column, of a JSON datatype. The JSON format of the data looks like this: {"creator": "1", "recipient": "2"} I want to join the users table using those fields to get the participants of the Chats. How do I do that? 回答1: Laravel has no native support for JSON relationships. I created a package

Laravel hasone relationship

久未见 提交于 2021-01-29 09:09:36
问题 I am trying to use hasone relation but getting null error. below is my code User Model: function profile() { $this->hasOne('App\Profile'); } Profile Model: function User() { return $this->belongsTo('App\User'); } Register Controller protected function create(array $data) { $user = User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), ]); if($user) { $profile = new Profile(); $profile->name = 'Fake Name'; $profile->father = 'Fake Father

Attach images to product variants when creating a new product Laravel

风格不统一 提交于 2021-01-29 07:07:58
问题 i'm having difficulty attaching images to variants when creating new products. for example a product A with variant A1 color blue size small images img1, img2 variant A2 color blue size medium image img3 img4 when I save this to the database, img1, img2, img3, img4 goes to both variant A1 and A2 instead of each variant to have its own images. How do I solve this? here is my controller public function variants(Request $request) { $data = $request->all(); foreach($data['title'] as $key =>

Resource Controller methods with model as parameter not working

两盒软妹~` 提交于 2021-01-29 05:56:46
问题 As in the basic Laracasts.com tutorial (Laracast 5.7 from scratch) I'm trying to use the following methods public function show(prototypes $prototypes) parameter to construct a view. However my view is created correctly but $prototypes is null. The route works well( /prototypes/1/edit ) and I ensured that a prototype object with the id 1 exists. I found some older solution which stated to use something like (integer $id) as parameter but this leads to some more code. It should work like this:

Laravel - Filter a collection by a dynamic field

可紊 提交于 2021-01-29 05:43:53
问题 The model has 3 fields that are attributes of the model and the 4th field is a dynamic field that is called "fullTitle" [ { "id": 1, "hours": 2000, "car_id": 3, "fullTitle": "Test", } } <?php namespace App; use App\Car; class VenderModel extends Model { use TranslationTrait; protected $guarded = ['*']; /** * The accessors to append to the model's array form. * * @var array */ protected $appends = [ 'fullTitle' ]; /** * Accessor for dynamic property fullTitle to use as selector name. * @param

Angular2 and Laravel CSRF protection

ⅰ亾dé卋堺 提交于 2021-01-29 03:14:36
问题 I have already read some topics And the problem I encountered is lies in this piece of code <meta property="csrf-token" name="csrf-token" content="{{ csrf_token() }}"> I'm using Angular2 as core engine, which sending AJAX requests to Laravel API and I'm not using blade templates - just .html files , so I can't call php function csrf_token() from html file So, I added a temporary solution by extending my /var/www/pandacrm/app/Http/Middleware/VerifyCsrfToken.php file public function handle(

Laravel 5.2, Maximum function nesting level

烈酒焚心 提交于 2021-01-29 03:06:22
问题 Please, help me to find what is going on. I just set up a basic Laravel project. It's a new fresh Laravel project (5.2.29) This is route.php Route::get('/', 'TestController@index'); This is the test controller class TestController extends Controller { public function index() { return view('home'); } } The home.blade.php is the one that comes with a fresh Laravel installation, the one printing "Laravel 5". When I add the 'web' middleware, as following Route::group(['middleware' => ['web']],

Laravel 5.2, Maximum function nesting level

青春壹個敷衍的年華 提交于 2021-01-29 03:03:24
问题 Please, help me to find what is going on. I just set up a basic Laravel project. It's a new fresh Laravel project (5.2.29) This is route.php Route::get('/', 'TestController@index'); This is the test controller class TestController extends Controller { public function index() { return view('home'); } } The home.blade.php is the one that comes with a fresh Laravel installation, the one printing "Laravel 5". When I add the 'web' middleware, as following Route::group(['middleware' => ['web']],

How does one get properties from related table as properties of it's own table in Laravel 5?

微笑、不失礼 提交于 2021-01-29 02:06:21
问题 The question might sound a little bit confusing but I don't know how to explain it better in one sentence. This describes basically what the problem is: I have a Users table which can contain 2 types of users. I know how I can separate by role. But here's the thing, users with role 1(editor_in_chief) have different attributes than users with role 2(reviewer). My idea was to create a table named 'reviewer_attributes' and 'editor_in_chief_attributes' and create a one-to-one relation with this

Route is redirecting to wrong page

杀马特。学长 韩版系。学妹 提交于 2021-01-28 21:13:20
问题 I'm working on Laravel 5 and I've set up the routes for all the pages. I have a dashboard that has certain icons which when clicked redirects to different pages. Now, this particular icon "Total Applications" is when clicked doesn't redirect to the page associated with it, i.e., total.blade.php but instead redirects to another page candidate.blade.php. I'm new to Laravel. I want that when I click the "Total Applications" page it should redirect to the page designated for it. I'm sharing the