davy_yg

davy_yg

Member Since 2 Years Ago

Jakarta

Experience Points 61,670
Experience Level 13

3,330 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 330
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

07 Sep
1 week ago

davy_yg started a new conversation Https

Hello,

I want to ask a question about this php config:

$config['base_url'] = "https://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

I am trying to config the base_url to https:// but it doesn't work, some of the codes still read the base_url as http://

I wonder why? This is CI by the way - but it has the same logic I believe.

06 Sep
1 week ago

davy_yg left a reply on Wishlist

I cannot call php artisan

D:\xampp72\htdocs\lekaeshop>php artisan route:list  
Could not open input file: artisan

davy_yg left a reply on Checking Laravel Version

D:\xampp72\htdocs\lekaeshop>php artisan list Could not open input file: artisan

composer.lock

"name": "laravel/framework",
"version": "v5.4.28"

davy_yg started a new conversation Checking Laravel Version

Hello,

I have a working ecommerce file created with laravel but I cannot check the laravel version of it.

D:\xampp72\htdocs\lekaeshop>laravel --version
Laravel Installer 2.1.0

D:\xampp72\htdocs\lekaeshop>php artisan --version
Could not open input file: artisan

Any clue why?

davy_yg started a new conversation Wishlist

When clicking the wishlist button I get this error:

(1/1) NotFoundHttpException

I wonder why?

store/index.blade.php

<a href="{{ url('/wishlist/add/'. $product->prod_id ) }}" class="button-wishlist">Wishlist</a>

WishlistsController.php

public function add(Products $product)
    {
    Wishlists::create([
      'prod_id' => $product->prod_id,
      'user_id' => auth()->user()->user_id
    ]);

    flash('Product added to wishlist.');

    return back();
    }

web.php

Route::get('/wishlists/add/{product}', '[email protected]');
05 Sep
1 week ago

davy_yg left a reply on Append

I can't understand where page request key comes from since it is not anywhere in the input form?

davy_yg started a new conversation Call To A Member Function Appends() On Null

Hello,

I get this error - Call to a member function appends() on null

on the following codes:

ProductsController.php

    if ($products_with_meta->count() == 0) {
                $products = null;
                return view('admin.products.products', compact('categories'), ['products' => $products->appends(request()->except('page'))]);
            }

How to fix it?

davy_yg left a reply on Javascript Code

I finally find it, it should be:

 $.get('subcategories/ajax/get', {

Checking through inspect - element -network

davy_yg left a reply on Javascript Code

That url should be correct

web.php

Route::get('/cpages/subcategories/ajax/get', '[email protected]_ajax');
04 Sep
1 week ago

davy_yg left a reply on Javascript Code

I already execute it just like the online version or perhaps it has something with the url:

function getParameterByName(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, "\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\+/g, " "));
    }

What the url should be on local?

It works online.

davy_yg left a reply on Javascript Code

I don't understand why in local there is no return of the ajax call.

SubCategoriesController.php

public function get_ajax()
    {
        $subcategories = SubCategories::where('cat_id', request('cat_id'))->get();
        return view('admin.products.ajax.subcategories', compact('subcategories'));
        }

admin.products.ajax.subcategories.blade.php

<option value="">Semua Sub-Kategori</option>
@foreach ($subcategories as $subcat)
<option value="{{ $subcat->subcat_id }}" @if($subcat->subcat_id == request('subcat_id')) selected @endif>
    {{ $subcat->subcat_name }}
    </option>
    @endforeach

davy_yg left a reply on Javascript Code

I wonder where the value of data comes from?

davy_yg left a reply on Javascript Code

In my localhost the result only shows the option with this message: Loading...

Only on the server I can see the sub categories.

davy_yg started a new conversation Javascript Code

Hello,

I cannot understand this script:

function changeSubcat() {
    $("#subcat_id").html('<option>Loading...</option>');
    $("#subcat_id").prop('disabled', false);
    var val = $("#cat_id").val();
    $.get('/cpages/subcategories/ajax/get', {
        cat_id: val
      })
      .done(function(data) {
        $("#subcat_id").html(data);
        if(getParameterByName('subcat_id') != "") {
          if(subcat_load_first == true) {
            $("#subcat_id").val(getParameterByName('subcat_id'));
            subcat_load_first = false;
          }
        }
      });
 }

What does this means: .prop('disabled', false); ?

and also: $.get('/cpages/subcategories/ajax/get', { cat_id: val })

How about this: .done(function(data) {

Thanks in advance.

davy_yg left a reply on Related Fields

Nevermind, I solved it.

        $men_products = Products::with('productMetas')
                    ->whereHas('productMetas', function ($query) {
                        $query->where('prod_meta_type', 1)
                              ->where('value', 1);
                        })
                    ->limit(env('FEATURED_PRODUCT'))
                    ->get();

davy_yg left a reply on Related Fields

(1/1) FatalThrowableError

Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')'

davy_yg left a reply on Query

I forget to ask another question:

$query = Products::query();
    $men_products = $query->productMetas()->where('prod_meta_type', 1)->where('value', 1)->get();

(1/1) BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::productMetas()

I wonder why I get the error message?

davy_yg started a new conversation Query

What does this query means?

 $query = Products::query();

davy_yg started a new conversation Related Fields

Hello,

I would like to select men's product:

$men_products = Products::first()->productMetas()->where('prod_meta_type', 1)->where('value', 1)->get();
    

The condition is in productMetas:

class Products extends Model
{
    use SoftDeletes;

protected $primaryKey = 'prod_id';
protected $guarded = ['prod_id'];
protected $dates = ['deleted_at'];

public function productMetas()
{
    return $this->hasMany(ProductsMeta::class, 'prod_id');
}

The above query isn't right since it use first which only captures the first row, if I delete the first then what the query looks like? I also wonder why the result only shows the field from ProductsMeta instead of showing the related field from products and ProductsMeta?

davy_yg left a reply on Table Relation

In order to relate the table do you have to call the function?

For example:

$product->productMetas

davy_yg started a new conversation Table Relation

Hello,

I would like to know if the following model automatically make relation products to other tables like ProductsMetas and productMainImage() ? So when you call product table automatically associate it with other tables also. IS that true?

Making relation

class Products extends Model
{
    use SoftDeletes;

protected $primaryKey = 'prod_id';
    protected $guarded = ['prod_id'];
    protected $dates = ['deleted_at'];

    public function productMetas()
    {
        return $this->hasMany(ProductsMeta::class, 'prod_id');
    }

    public function productMainImage()
    {
        return $this->hasOne(Images::class, 'img_id', 'prod_main_img');
    }

In addition, what is this for?

protected $guarded = ['prod_id'];

davy_yg started a new conversation Append

Any clue what this code means:

$products->appends(request()->except('page'))

davy_yg left a reply on ProductMetas

Sublime can do that. Find in Files. Could search for the whole project.

I still wonder if $product->productMetas can call the model function AND the product attributes. So that is true right?

davy_yg left a reply on ProductMetas

sublime can do so using Find in File. I am using Sublime.

I found this:

Products.php

 public function productMetas()
    {
    return $this->hasMany(ProductsMeta::class, 'prod_id');
    }

davy_yg left a reply on ProductMetas

What is a grep tool and what is it for? I only use laravel for 1 year and still learning. How could you process $product->productMetas before relating it to another table?

davy_yg left a reply on Limit(env

You are right! Thanks

.env

FEATURED_PRODUCT=8

davy_yg started a new conversation ProductMetas

Hello,

Please help me understand this codes:

public function products_details(Products $product)
    {

dd($product);

    Products::where('prod_id', $product->prod_id)->increment('prod_seen');

    $related_products = ProductsMeta::get_related($product->productMetas, $product->prod_id);

when I dd($product); I cannot find productMetas I wonder where $product->productMetas comes from?

 #attributes: array:16 [▼
    "prod_id" => 11
    "prod_name" => "SUNNY BLOUSE 031 SZ 94"
    "prod_main_img" => "26"
    "prod_price" => 100000
    "prod_weight" => 1
    "prod_description" => "Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right ▶"
    "prod_rating" => null
    "prod_featured" => 1
    "prod_stockable" => 0
    "prod_stock" => null
    "prod_availability" => 1
    "prod_type" => null
    "prod_seen" => 36
    "deleted_at" => null
    "created_at" => "2017-09-25 13:15:17"
    "updated_at" => "2019-01-08 06:04:36"
]

davy_yg started a new conversation Prod Id

Hello,

I have this codes:

web.php

//Store Products
Route::get('/product/{product}', '[email protected]_details');

StoreController.php

public function products_details(Products $product)
{

Products::where('prod_id', $product->prod_id)->increment('prod_seen');

See I cannot understand when someone pass the id such as calling /product/5 will it automatically call the product with the id of 5? If so, why still capturing the id with $product->prod_id ?

Thanks in advance.

03 Sep
1 week ago

davy_yg started a new conversation Limit(env

Hello,

I have this codes:

 $featured_products = Products::where('prod_featured', 1)->limit(env('FEATURED_PRODUCT'))->get();

I wonder where do you get env('FEATURE_PRODUCT') from? I cannot find it in the table. I can only find prod_featured

davy_yg started a new conversation Auth()->login

What is the difference between auth()->attempt() and auth()->login()

I need some example of auth()->login() to understand

Auth\StatefulGuard.php

    public function attempt(array $credentials = [], $remember = false);

    /**
    * Log a user into the application without sessions or cookies.
    *
    * @param  array  $credentials
    * @return bool
    */

public function once(array $credentials = []);

    /**
    * Log a user into the application.
    *
    * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
    * @param  bool  $remember
    * @return void
    */

public function login(Authenticatable $user, $remember = false);

    /**
    * Log the given user ID into the application.
    *
    * @param  mixed  $id
    * @param  bool   $remember
    * @return \Illuminate\Contracts\Auth\Authenticatable
    */
02 Sep
2 weeks ago

davy_yg left a reply on Undefined Property: StdClass::$image

I finally figure out why. I have similar file with different folder. I read the wrong files.

davy_yg left a reply on Undefined Property: StdClass::$image

I can't understand why my sublime still reading the old memory while I already edit the codes. It keeps showing me the old error from:

in dbe595f2a72e7be9c02504364c8741b92e669a34.php (line 26)

I already try to delete the storage view and clean cache but it still remains.

davy_yg left a reply on Undefined Property: StdClass::$image

I want the url (from images.url)

Looks like the error comes from on the frontend on this code:

@foreach($posts as $post)

davy_yg started a new conversation Undefined Property: StdClass::$image

Hello,

I get this: Undefined property: stdClass::$image

error message after Add this code:

 $posts = DB::table('posts')
                ->join('images', 'posts.main_image_id', '=', 'images.img_id')
                ->select('posts.*', 'images.url')
                ->get();

What's lacking?

30 Aug
2 weeks ago

davy_yg started a new conversation Online Shop

Hello,

I am having something strange on this online shop.

navigation.blade.php

<ul class="sf-menu">
      <li class="deeper parent current"><a href="{{ url('/') }}">Home</a></li>
      <li><a href="{{ url('/catalog') }}">Catalog</a></li>
      
      @foreach($categories as $category)
        <li>
          <a href="{{ url('/catalog/'. $category->cat_id)}}">
                                    {{ $category->cat_name }}
                                </a>
          @if($category->subCategories->count() != 0)

            <ul>
            @foreach($category->subCategories as $subcat)

                <li><a href="{{ url('/catalog/'. $category->cat_id .'/'. $subcat->subcat_id)}}">{{ $subcat->subcat_name }}</a></li>

            @endforeach
            </ul>

          @endif

        </li>
      @endforeach
      <li><a href="{{ url('/blog') }}">Blog</a></li>
      <li><a href="{{ url('/contact') }}">Contact</a></li>
    </ul>

In the controller:

StoreController.php

public function index()
 {
    $new_products = Products::latest()->limit(env('NEW_PRODUCT'))->get();
    $popular_products = Products::orderBy('prod_seen', 'desc')->limit(env('POPULAR_PRODUCT'))->get();
    $featured_products = Products::where('prod_featured', 1)->limit(env('FEATURED_PRODUCT'))->get();
    //dd($popular_products);
    return view('store.index', compact('new_products', 'popular_products', 'featured_products'));
 }

When I var_dump the categories there are a lot in it, but I do not know where it comes from. Please gives me some ideas.

Route::get('/', '[email protected]');

In the store index it includes navigation.blade.php. This must be something advance. Where does $categories comes from?

Please help.

27 Aug
2 weeks ago

davy_yg started a new conversation Too Few Arguments To Function

"Too few arguments to function App\Http\Controllers\API\CustomerAPIController::App\Http\Controllers\API{closure}(), 1 passed and exactly 2 expected"

Any clue why I am getting this error message?

CustomerAPIController.php

  public function SearchCustomer(Request $request)
  {

        $input = $request->all();

        $group_id = @$input['group_id'];
        $search = @$input['search'];
        $maxdata = @$input['maxdata'];


        // $sql = Customer::where('group_id', 'like', $group_id)->orwhere('name', 'like', '%'.$name.'%')->orwhere('address', 'like', '%'.$address.'%')->orwhere('email', 'like', $email)->orwhere('phone', 'like', $phone)->orwhere('notes', 'like', '%'.$notes.'%')->paginate($maxdata);
        $sql = DB::table('ms_customer');

        if($group_id != null && $search != null){

            $sql = $sql->where('group_id', '=', $group_id)
                       ->where(function ($query, $search) {
                            $query->orwhere('name', 'like', '%'.$search.'%')
                                  ->orwhere('address', 'like', '%'.$search.'%')
                                  ->orwhere('email', 'like', '%'.$search.'%')
                                  ->orwhere('phone', 'like', '%'.$search.'%')
                                  ->orwhere('notes', 'like', '%'.$search.'%');
                        });
        }            
        
        if($maxdata != null){
            $sql = $sql->limit($maxdata);
        }               
       
        $sql_arr = $sql->get()->toArray();

       
        return $this->sendResponse($sql_arr, 'Customer retrieved successfully');
      }
21 Aug
3 weeks ago

davy_yg left a reply on Php Artisan

D:\xampp72\htdocs\redbuzz>php artisan

'php' is not recognized as an internal or external command, operable program or batch file.

davy_yg left a reply on Php Artisan

D:\xampp72\htdocs\redbuzz>laravel

'laravel' is not recognized as an internal or external command, operable program or batch file.

davy_yg started a new conversation Php Artisan

Hello,

When I typed php artisan in command prompt it does not recognize the syntax, any clue why?

What do I need to install to make it works?

20 Aug
3 weeks ago

davy_yg started a new conversation Elorest Postman Or

http://*******/public/api/elorest/Models/Supplier?where=name,like,abc&where=email,like,abc.gmail.com&select=&get=

this syntax works when using & and now I want to change it to or yet it does shows error when I do that.

SQL: select * from ms_supplier where like name like abc||where=email ms_supplier.deleted_at is null)

I wonder why?

19 Aug
4 weeks ago

davy_yg started a new conversation Elorest - Put

Hello,

Anyone understand how to edit data in elorest? (using PUT)

https://github.com/dandisy/elorest

I get the following error when trying to edit.

Class 'App\Models' not found

What does it mean?

15 Aug
1 month ago

davy_yg started a new conversation API Login

Hello,

I create api for login that returns username and message retrieved user successfully:

public function index(Request $request)
{
 
    $data = $request->all();
    $data['email'] = $request->email;
    $password = bcrypt($request->password);

    $User = User::where('email', $data['email']) and where('password', $password)->get();

    if($User != null){

        return $this->sendResponse($data->toArray(), 'Users retrieved successfully');    
    }
    
   }

I am not sure if I write this line correctly:

$User = User::where('email', $data['email']) and where('password', $password)->get();

please help me correct it?

davy_yg left a reply on Elorest

I am working on top of someone else code. I have to build new api. The previous developer uses elorest. I have used laravel for around 1 year. I have no choice but to use elorest.

Most of the tutorial I watches only uses echo json. Elorest seems to be different when calling the api.

davy_yg left a reply on Has

So it's checking if there is a transaction row connected to the transaction table?

davy_yg started a new conversation Has

Cek this code:

$seller = Seller::has('transactions')->findOrFail($id);

has('transaction') is it checking the existance of transactions table?

davy_yg left a reply on Elorest

I read the documentation but still do not understand the syntax to call the api. I working on someone else program:

http://*/public/oauth/[email protected]&password=&grant_type=password&scope=[]&client_id=1&client_secret=2ZxtO4C4pyfeBsRZKO5q9AcSAPKPmHU8bacWThKf

I cannot understand where do you get oauth/ and token ?

and there is another one:

http://*******/public/api/products?query[a][function]=get

This link works but not understandable. Since I have to get another similar api and create the api

What is the point of using elorest? and why not using normal api?

14 Aug
1 month ago

davy_yg started a new conversation Elorest

Hello,

What is elorest is for?

Elorest::routes();

Elorest::routes([ 'middleware' => ['auth:api', 'throttle:60,1'], // 'only' => ['post', 'put', 'patch', 'delete'], 'except' => ['get'] ]);

There isn't much information on google about it.

davy_yg started a new conversation Decrypting Bcrypt Password

Hello,

I have been looking for away to decrypt bcrypt password online but I cannot understand why they keep asking for a string to check against?

When encrypting it as simple as this:

$user->password = bcrypt($request->password); $user->save();

What am I missing?

davy_yg left a reply on Casts

I still do not get the point of using casts if we can use validation to validate the data.

13 Aug
1 month ago

davy_yg started a new conversation Api Routes

Hello,

I would like to check:

routes/api.php

Route::get('reports/documents', '[email protected]');   

Route::resource('customer_groups', 'CustomerGroupAPIController');

How to know if my api works or not using these routes. Is it enough to type: www.mainurl.com/reports/documents and www.mainurl.com/customer_groups

?