dimanche 27 octobre 2019

Why am I getting a carbon instance from a collection?

I have this collection of riv_queries.

$riv_queries = RivQuery::where('id', Auth::user()->id)->first();
RivQuery {#157 ▼

#attributes: array:12 [▼
    "id" => 88
    "riv_from" => "2019-10-15"
    "riv_to" => "2019-10-15"
    "department_id" => 109
    "type_id" => 0
    "record_type_id" => 1
    "cal_year" => 2018
    "accordion" => 0
    "city_id" => 0
    "region_id" => 8
    "prov_id" => 837
    "tx_date" => "2019-10-15"
  ]

My problem is whenever I want to get 'riv_to' or 'riv_from' I always get this as a result

dd($riv_queries->riv_to);
Carbon @1571068800 {#638 ▼
  date: 2019-10-15 00:00:00.0 Asia/Manila (+08:00)
}

But i only expect result like this

"2019-10-15"

What am I doing wrong?



via Chebli Mohamed

@Yield doesnt seem to work on Laravel Snippets

Im trying to make things work for a laravel app page but it seems like it gave me an error. The following below are my codes. NOTE: I have already installed the extension for Laravel Snippet.

enter image description here

Can you guys give me advise on this? thank you.



via Chebli Mohamed

How to create a subdomain automatically in Laravel

I am creating a SaaS app using Laravel and I am trying to create subdomains for each user signup. For example, 1. User comes to www.somewebsite.com and signs up 2. During the signup user provides their business name e.g. mybiz 3. I want my Laravel app to dynamically create a dynamic subdomain mybiz.somewebsite.com 4. Whenever user logs into the website they are automatically redirected to mybiz.somewebsite.com and they stay on this URL during the entire session.

At no time I as an admin would like to create a subdomain manually. I am using Apache on Ubuntu for my Laravel install.



via Chebli Mohamed

how can i fix "Trying to get property of non-object"

i have a favorite list in my website for the users and they can add their favorite house to the wishlist

it goes well but he can not see the wishlist page and an error comes like this:

Trying to get property 'image' of non-object

it's my relations

class Home extends Model {

protected $guarded = [];



public function favorite(){

    return $this->hasMany(favorite::class,'house_id');
}

}

class favorite extends Model {

protected $guarded = [];

public function house(){

    return $this->belongsTo(home::class);
}

}

my index function in controller:

public function index() {

     $favorite=favorite::where('user_id',auth()->user()->id)->get();

     return view('favorite.index',compact('favorite'));
}

my index:

@foreach($favorite as $fav)

                                <tr>
                                    <td>
                                        <a href="property-detail.html"><img src="" alt=""
                                                                            width="100"></a>
                                    </td>
                                    <td><a href="property-detail.html"></a></td>
                                    <td>خانه خانواده</td>
                                    <td>اجاره</td>
                                    <td>
                                        <div class="price"><span></span><strong>تومان</strong>
                                        </div>
                                    </td>
                                    <td>
                                        <a href="#" class="action-button"><i class="fa fa-ban"></i> <span>حذف</span></a>
                                    </td>
                                </tr>
                            @endforeach


via Chebli Mohamed

create index for following LARAVEL eloquent query

Hi please help me out for creating an index for the following query

                        $products = \App\items::with([
                 'item_store' => function ($query) {
                $query->select('size', 'item_id', 'item_store_id');
              },

            'pics' => function ($query) {
                $query->select('img_url', 'item_id');
            },

            'brand' => function ($query) {
                $query->select('item_id', 'brand_id');
            },
            'brand.brand' => function ($query) {
                $query->select('brand_id', 'brand_name');
            }

             ])
         ->select('item_id', 'short_name', 'price','price_above')
         ->orderBy('Price', 'Asc')->whereIn('category_id', $arr)
         ->groupBy('Sku')
         ->paginate(20);

my database structure is [st] https://screenshots.firefox.com/JAmaKENMYRhQkEjx/ourweds.com



via Chebli Mohamed

how can chart js call datasets base on value from select option?

trying to get value from select option dynamically then use the value to create new chart depend on value

doesn't work

"new Chart(context).Bar(callchart);"

but this works

"new Chart(context).Bar(keyboard);"

when you call it statically

@foreach($item_name as $in) item_name}}" value=""> @endforeach

var Mouse= { labels: ['January','February','March'],

datasets: [
    {
      fillColor: "rgba(220,220,220,0.2)",
      strokeColor: "rgba(220,220,220,1)",
      pointColor: "rgba(220,220,220,1)",
      pointStrokeColor: "#fff",
      pointHighlightFill: "#fff",
      pointHighlightStroke: "rgba(220,220,220,1)",
      data: [30,120,90]
    },
]
};

var keyboard = { labels: ['March', 'Apr', 'May'],

datasets: [
    {
      fillColor: "rgba(220,220,220,0.2)",
      strokeColor: "rgba(220,220,220,1)",
      pointColor: "rgba(220,220,220,1)",
      pointStrokeColor: "#fff",
      pointHighlightFill: "#fff",
      pointHighlightStroke: "rgba(220,220,220,1)",
      data: [50,100,140]
    },
]
};

var Spoon ={ labels: ['June', 'July', 'August'],

datasets: [
    {
    fillColor: "rgba(220,220,220,0.2)",
    strokeColor: "rgba(220,220,220,1)",
    pointColor: "rgba(220,220,220,1)",
    pointStrokeColor: "#fff",
    pointHighlightFill: "#fff",
    pointHighlightStroke: "rgba(220,220,220,1)",
    data: [1,2,3]
    },
]
};

var context = document.querySelector('#graph').getContext('2d');

if(window.bar != undefined) window.bar.destroy();

window.bar = new Chart(context).Bar(keyboard);

$("select").on('change', function() {

//GETING VALUE FROM SELECT OPTION

var callchart =this.value;

var context = document.querySelector('#graph').getContext('2d');

if(window.bar != undefined) window.bar.destroy();

//CREATING CHART USING VALUE FROM SELECT OPTION

window.bar = new Chart(context).Bar(callchart);

});

Uncaught TypeError: Cannot read property 'length' of undefined



via Chebli Mohamed

Uncaught TypeError: Cannot redefine property: $router

I am new to vue.js 2 and laravel and I am following a tutorial. I faced the error below and already know the reason -it's because of redefining or using vue.js-. But I am using my app.js file once and not using CDN in any other script tags. I also saw this question here but did not help since I am using app.js once.

here is my code below: app.js


require('./bootstrap');

window.Vue = require('vue');
import VueRouter from 'vue-router';

Vue.use(VueRouter);

let routes = [
    {path:'/dashboard', component:require('./components/Dashboard.vue')},
    {path:'/profile', component:require('./components/Profile.vue')}
]
const router = new VueRouter({
    mode:'history',
    routes
})



const app = new Vue({
    el: '#app',
    router
});

It's my master.blade.php (my master layout that home.blade.php extends it):


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="csrf-token" content="">
  <title>AdminLTE 3 | Starter</title>

  <link rel="stylesheet" href="/css/app.css">
</head>
<body class="hold-transition sidebar-mini">
<div id="app"class="wrapper">
  <nav class="main-header navbar navbar-expand navbar-white navbar-light">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" data-widget="pushmenu" href="#"><i class="fas fa-bars"></i></a>
      </li>
    </ul>
    <form class="form-inline ml-3">
      <div class="input-group input-group-sm">
        <input class="form-control form-control-navbar" type="search" placeholder="Search" aria-label="Search">
        <div class="input-group-append">
          <button class="btn btn-navbar" type="submit">
            <i class="fas fa-search"></i>
          </button>
        </div>
      </div>
    </form>
  </nav>
  <aside class="main-sidebar sidebar-dark-primary elevation-4">
    <a href="index3.html" class="brand-link">
      <img src="dist/img/AdminLTELogo.png" alt="AdminLTE Logo" class="brand-image img-circle elevation-3"
           style="opacity: .8">
      <span class="brand-text font-weight-light">AdminLTE 3</span>
    </a>
    <div class="sidebar">
      <div class="user-panel mt-3 pb-3 mb-3 d-flex">
        <div class="image">
          <img src="dist/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image">
        </div>
        <div class="info">
          <a href="#" class="d-block"></a>
        </div>
      </div>
      <nav class="mt-2">
        <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
          <li class="nav-item">
            <a href="#" class="nav-link">
              <i class="nav-icon fas fa-tachometer-alt"></i>
              <p>
                Dashboard
                <span class="right badge badge-danger">New</span>
              </p>
            </a>
          </li>
          <li class="nav-item">
            <a href="#" class="nav-link">
              <i class="nav-icon fas fa-user"></i>
              <p>
                Profile

              </p>
            </a>
          </li>
          <li class="nav-item has-treeview">
            <a href="#" class="nav-link active">
              <i class="nav-icon fas fa-cog"></i>
              <p>
                Management
                <i class="right fas fa-angle-left"></i>
              </p>
            </a>
            <ul class="nav nav-treeview">
              <li class="nav-item">
                <a href="#" class="nav-link">
                  <i class="far fa-circle nav-icon"></i>
                  <p>Active Page</p>
                </a>
              </li>
              <li class="nav-item">
                <a href="#" class="nav-link">
                  <i class="far fa-circle nav-icon"></i>
                  <p>Inactive Page</p>
                </a>
              </li>
            </ul>
          </li>
          <li class="nav-item ">
            <a href="#" class="nav-link">
              <i class="nav-icon fas fa-power-off "></i>
              <p>
                Logout

              </p>
            </a>
          </li>

        </ul>
      </nav>
    </div>
  </aside>
  <div class="content-wrapper">
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">Starter Page</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active">Starter Page</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="container-fluid">
          <router-view></router-view>
      </div>
    </div>
  <aside class="control-sidebar control-sidebar-dark">
    <div class="p-3">
      <h5>Title</h5>
      <p>Sidebar content</p>
    </div>
  </aside>

  <footer class="main-footer">
    <div class="float-right d-none d-sm-inline">
      Anything you want
    </div>
    <strong>Copyright &copy; 2014-2019</strong> All rights reserved.
  </footer>
</div>
<script type="application/javascript" src=""></script>
</body>
</html>

and my home.blade.php only has @extends('layouts.master')

I included the master.blade.php completely so to show only one time included the app.js file which is using vuejs2.



via Chebli Mohamed