swimmer

swimmer

Member Since 1 Year Ago

Experience Points
4,970
Total
Experience

30 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
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 1
4,970 XP
Jun
01
18 hours ago
Activity icon

Started a new Conversation Java Script Directly With Laravel Dusk

Is there a way to type Java script directly with Laravel Dusk for example


document.getElementById("home-user-image").innerHTML  = 'do your magic';

I am not interested in using the Laravel PHP way of doing things


->type('#home-user-image, do your magic') 

Just to put in directly classic JS.

May
31
1 day ago
Activity icon

Replied to Delete All Fodders And Sub Folders

@tykus

Thank you that works. I think I read somewhere that having too many Facades is not good for the application. Is that true?

Activity icon

Replied to Delete All Fodders And Sub Folders

@tykus How would I do that?

Activity icon

Started a new Conversation Delete All Fodders And Sub Folders

I would like to delete all fodders and sub folders in a public folder. I am trying to use

    $photo_path = public_path().'/dusk_upload_photo/'; 
                    
        File::deleteDirectory($photo_path);

I have use Illuminate\Filesystem\Filesystem;

However I’m getting the following error

Class 'App\File' not found

What am I doing wrong?

May
27
5 days ago
Activity icon

Replied to Cannot Catch JSON

I got it to work

$json = $request->file('json')->get(); 
$array = json_decode($json, true);

Thank you for your help

Activity icon

Replied to Cannot Catch JSON

Hi,

Thank you for your suggestion however when I try dd($request->file('json'));

I do not get the data in the JSON I uploaded.

How do I extract the JSON and converted to a PHP array?

This is what I get


Illuminate\Http\UploadedFile {#1179 ▼
  -test: false
  -originalName: "photo_export_json.json"
  -mimeType: "application/json"
  -error: 0
  #hashName: null
  -pathName: "C:\xampp\tmp\phpFF9B.tmp"
  -fileName: "phpFF9B.tmp"
  path: "C:\xampp\tmp"
  filename: "phpFF9B.tmp"
  basename: "phpFF9B.tmp"
  pathname: "C:\xampp\tmp\phpFF9B.tmp"
  extension: "tmp"
  realPath: "C:\xampp\tmp\phpFF9B.tmp"
  aTime: 2020-05-27 08:48:57
  mTime: 2020-05-27 08:48:57
  cTime: 2020-05-27 08:48:57
  inode: 37999121855948280
  size: 3435
  perms: 0100666
  owner: 0
  group: 0
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
  linkTarget: "C:\xampp\tmp\phpFF9B.tmp"
}
Activity icon

Started a new Conversation Cannot Catch JSON

I am trying to upload a JSON file from my local computer

However when I try to dd the JSON in my store in my controller

I have issues

I tried the following methods

dd($request["json"]); I am unable to pull the

when I try dd($request->input('json'));

I get “null”

What am I doing wrong?

This is my form


<form action="{{url('upload_json')}}" method="POST" novalidate="novalidate" autocomplete="off" enctype="multipart/form-data">
  @csrf  

  <div class="custom-file">
    <input name="json" type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
    <label class="custom-file-label" for="inputGroupFile01">Upload JSON</label>
  </div>

  <div class="form-group">
    <small class="text-muted">The JSON must be max size: 100k</small><br>
    <span class="text-danger">{{ $errors->first('json') }}</span>
</div>


  <a class="btn btn-secondary" href="{{ url('') }}">Cancel</a>
  <input class="btn btn-primary" name="submit" type="submit" value="Upload JSON">  
</form>

This is my store method


  public function store(Request $request)
    {
        // dd('I am in the dd  store');
        // dd($request["json"]);
        dd($request->input('json'));
    }
May
26
6 days ago
Activity icon

Started a new Conversation Upload A JSON To A Form

I set up a form that I upload A JSON file to it

I am trying to test how I can analyze my file it seems like it’s never submitted to the next form.

What am I doing wrong?

This is my form to upload JSON



<h1 class="title"> Upload your Json</h1>
<div class="upload_file">
<form action="{{ url('') }}" method="POST" novalidate="novalidate" autocomplete="off" enctype="multipart/form-data">
  @csrf  

  <div class="custom-file">
    <input type="file" class="custom-file-input" id="customFile">
    <label class="custom-file-label" for="customFile">Choose file</label>
  </div>

  <a class="btn btn-secondary" href="{{ url('') }}">Cancel</a>
  <input class="btn btn-primary" name="submit" type="submit" value="Upload JSON">  
</form>

This is my controller


 public function index()
    {
        return view('forms.upload_json');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {   
        dd('I am in the dd');
        dd($request);
        return view('forms.upload_json');
    }
May
21
1 week ago
Activity icon

Started a new Conversation Click On Button In Dusk

Hello, I have the following HTML in Laravel Dusk


<button class="department btn-dept" id="wedding" data-department="wedding" data-ptags="occasion:wedding">
                                <span class="show-for-large-up">Weddings</span>
                                <span class="show-for-medium-only">Weddings</span>
                                <span class="show-for-small-only">Weddings</span>
                                <span class="show-for-plus-only">Weddings</span>
                            </button>

And I would like to click on this button in Laravel Dusk I tried the following options

->click('Weddings') ->click('.department btn-dept') ->click('#wedding')

What other options are there?

May
20
1 week ago
Activity icon

Started a new Conversation Laravel Dusk ERRORS!

I started playing around with Laravel dusk

I enabled live view of my browser where I can see browser behavior when doing commands in Dusk

I tried the following command “php artisan dusk”

However I get the following error: C:\xampp\htdocs\try\tests\Browser\TryTest.php:23

ERRORS! Tests: 1, Assertions: 0, Errors: 1.

My class is


<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class TryTest extends DuskTestCase
{
    /**
     * A Dusk test example.
     * @test
     * @return void
     */
    public function testExample()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/public/')
                    // ->pause(1000)
                    ->assertSee('Laravel');

        });
    }
}

In the .env I have APP_URL=http://localhost:8080/try/

What am I doing wrong?

May
19
1 week ago
Activity icon

Replied to Laravel Dusk Test File Not Working

I found the issue I should have put in .env my local host and the name of the Laravel project in my case "try"

"http://localhost:8080/try"

Activity icon

Started a new Conversation Laravel Dusk Test File Not Working

I tried to install Laravel Dusk with Laravel 5.8

I found that I need to change my .env APP_URL

I tried the following two changes To put the value that I get when I try

php artisan serve

and also to put the public route as recommended at the following site

http://terrapinssky.blogspot.com/2017/08/laravel55duskresolved-default.html

However both situations I received an error The error message is


There was 1 failure:

1) Tests\Browser\ExampleTest::testBasicExample
Did not see expected text [Laravel] within element [body].
Failed asserting that false is true.

C:\xampp\htdocs\try>php artisan dusk
Warning: TTY mode is not supported on Windows platform.
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.


DevTools listening on ws://127.0.0.1:60999/devtools/browser/eb4ec27d-baa8-488a-9662-fd5f51a9e6b4
F                                                                   1 / 1 (100%)

Time: 6.1 seconds, Memory: 16.00 MB

There was 1 failure:

1) Tests\Browser\ExampleTest::testBasicExample
Did not see expected text [Laravel] within element [body].
Failed asserting that false is true.

C:\xampp\htdocs\try\vendor\laravel\dusk\src\Concerns\MakesAssertions.php:173
C:\xampp\htdocs\try\vendor\laravel\dusk\src\Concerns\MakesAssertions.php:144
C:\xampp\htdocs\try\tests\Browser\ExampleTest.php:20
C:\xampp\htdocs\try\vendor\laravel\dusk\src\Concerns\ProvidesBrowser.php:68
C:\xampp\htdocs\try\tests\Browser\ExampleTest.php:21

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

What am I doing wrong?

May
17
2 weeks ago
Activity icon

Started a new Conversation Laravel Dusk Simulate Photo Upload

I was thinking of using Laravel dusk to build a bot that will simulate upload of photos to a website that I do not own.

Is Laravel dusk the right tool?

You can watch a video explaining what I’m trying to accomplish at the following link: https://drive.google.com/file/d/1vTtmAZwHogO21pHxC4UGUJMooBGMRuqZ/view?usp=sharing

The HTML that allows to upload photos on external websites is:

<label class="btn btn-primary btn-block">
                                <span class="hide-for-small">Add from computer</span>
                                <span class="show-for-small">Add from mobile</span>
                                <input type="file" class="photo" id="uploadr" multiple="" accept="image/*">
                            </label>

May
12
2 weeks ago
Activity icon

Replied to Paginate Only Returns Three Products

@Snapey I just tested it and change my code and it works thank you.

Activity icon

Replied to Paginate Only Returns Three Products

The issue is when I try

 static public function get_categories_cms()
 {
  // $content = categorie::all();
  $pagi_jump = 3;
  
  $content = categorie::paginate(); 
  


  if($content -> count() > $pagi_jump)
  {
    $data['content'] =  $content;
    $data['pagi_jump'] = true;

    return $data;

  }

    else {
        
        $data['content'] = $content;
        $data['pagi_jump'] = false; 

        return $data;
       
    }   

 }

In blade I have the following


  @if($pagi_jump)   
  {{$content->links()}}
@endif

I get in my blade template all 6 items and not the paginate bar to go those the items.

Activity icon

Started a new Conversation Paginate Only Returns Three Products

I am trying to use paginate

I understood that paginate only work on query not a collection I tried originally to use


$content = categorie::all();

But then it created issues

So I tried the following:

static public function get_categories_cms()
 {
  // $content = categorie::all();
  $pagi_jump = 3;
  $content = categorie::paginate(); 
  


  if($content -> count() > $pagi_jump)
  {
    $content = categorie::paginate($pagi_jump);
    $data['content'] =  $content;
    $data['pagi_jump'] = true;
    return $data;

  }

    else {
        
        $data['content'] = $content;
        $data['pagi_jump'] = false; 
        return $data;
       
    }   

 }

} 

The issue with this code is that it only returns 3 products even though I have 6 products.

What am I doing wrong?

May
11
3 weeks ago
Activity icon

Replied to Paginate On Array

@wheesnoza Thank your solution works

Activity icon

Started a new Conversation Paginate On Array

I have the following code

$query = 'SELECT c.title as c_title,p.*
        FROM categories as c, products as p
        WHERE c.id = p.category_id
        ORDER BY c.title ASC';

        

        $data['products'] = DB::select($query); 
        
        
         
      // This variable defines how many products by default will be inside the paginate
      $pagi_jump = 10;
          
    //   $users = DB::table('users')->paginate(15);
      $data['products'] = $data['products']->paginate(10);

When I try to use paginate I get on error that:

“Call to a member function paginate() on array”

What am I doing wrong?

Dose paginate work with on array?

May
08
3 weeks ago
Activity icon

Started a new Conversation Trying To Fetch Order Information For A Particular User

I am trying to fetch order information for a particular user from my order table.

When I put in the following query directly into MYSQL php Admin

It works

SELECT o.* FROM orders as o WHERE ‘1’ = o.user_id ORDER BY o.user_id ASC

However if try the following $u_id = strval(Session::get('user_id'));

    $query = 'SELECT o.*
    FROM  orders as o
    WHERE $u_id = o.user_id
    ORDER BY o.user_id ASC';

    
    $data['content'] = DB::select($query); 

I get the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '$u_id' in 'where clause' (SQL: SELECT o.* FROM orders as o WHERE $u_id = o.user_id ORDER BY o.user_id ASC) Previous exceptions

SQLSTATE[42S22]: Column not found: 1054 Unknown column '$u_id' in 'where clause' (42S22)

I know that $u_id = ‘1’;

Therefore I should get the same thing.

What am I doing wrong?

Activity icon

Replied to Hash Login System

@Snapey

you mentioned that “null or '' submitted in your change password form will still produce a hash”

Can you please explain more what you mean by this I don’t understand.

Activity icon

Replied to Hash Login System

@guybrush_threepwood

  1. The code that I put in the previous post are my App/User.php I put there all the relevant methods.
  2. setPasswordAttribute() I do not have such a method 3)After checking my config/hashing.php I have the following 'driver' => 'bcrypt'

What now?

Activity icon

Replied to Hash Login System

@guybrush_threepwood @Snapey

Here is my model

public static function save_new_user($request){
         
        
         if($request['password'] == $request['password_confirmation']){
           
           
           
           // Cerat user
            
            $user = New User();
            $user->name = $request['name'];
            $user->email = $request['email'];
            $user->password = bcrypt($request['password']);
            $user->image = 'default.jpg';
            $user->save();   

         }
         
         

         public static function validate_user($email,$pass)
         {
   
             $valid = false;
             $user = DB::table('users AS u')
             ->join('users_roles AS ur','u.id','=', 'ur.uid')
             ->where('u.email','=',$email)
             ->first();
              
   
             $hashedPassword = $user->password;
             
           //  dd(Hash::check($pass, $hashedPassword));   
                
                 if(!empty ($user) && $pass == $user->password) 
                 {
                   
   
                    
                   $valid = true;
   
                  
                   Session::put('user_id',$user->id);
                   Session::put('user_name',$user->name);
   
                 
                   if($user->rid == 1) Session::put('is_admin',true);
                   
                   
                   Session::flash('success_message','Welcome back '.$user->name);
   
                  
   
               }
                
                   return $valid;
      
         }

         

         public static function update_user($request)
      
      
         {  
   
          
           $user_id = Session::get('user_id');
            
         
           User::upload_profile_image($request); 
          
   
           $user = User::find($user_id);
           $user->name = $request['name'];
           $user->email = $request['email'];
           $user->password = bcrypt($request['password']);
           $user->save();

         }

Can you see what I’m doing wrong?

Activity icon

Started a new Conversation Hash Login System

I have a login system With is using Hash When I try to re-log in with the password I’m not able to successfully login with Hash I’m checking the hash against my database with the following code

$hashedPassword = $user->password;
Hash::check($pass, $hashedPassword));

I have a video explaining this issue better which can be found at the following link:

https://drive.google.com/file/d/1yPP00EFEKw8_B-kHuYaVjVJf_7nhl0WL/view?usp=sharing

If you watch my video I’m sure you will understand my problem.

Thank you for your help

May
07
3 weeks ago
Activity icon

Replied to Photo For Form Not Passing

Thank you that works

Activity icon

Started a new Conversation Photo For Form Not Passing

I am trying to submit a form with a photo. It seems like the photo information is not passing in the request

When I try dd($request->toArray());

I do not get the photos information the only thing I get is the photo name.

This is my form:

 <div class="col-md-4">
   <form action="" method="POST" novalidate="novalidate" autocomplete="off">
     @csrf

    
     <div class="form-group">
       <img class="edit_profile_imag" style="max-width:300px;width:300%" src="{{asset('photos/profile/'.$content['image'])}}"  alt="{{ $content['title'] }}">         
     </div> 

     
     <div class="form-group">
       <label for="name">* Name:</label>
       <input value="{{$content['name']}}" class="form-control" type="text" name="name" id="name">
       <span class="text-danger">{{ $errors->first('name') }}</span>
     </div>
     <div class="form-group">
       <label for="email">* Email:</label>
     <input value="{{$content['email']}}" class="form-control" type="email" name="email" id="email">
     <span class="text-danger">{{ $errors->first('email') }}</span>
     </div>      
     <div class="form-group">
       <label for="confirm-password">*New Password:</label>
       <input class="form-control" type="password" name="new_password" id="new_password">
       <small class="text-muted">Password must be more than six characters</small><br>
       <span class="text-danger">{{ $errors->first('new_password') }}</span>
     </div>   

     <div class="form-group">
       <label for="confirm-password">*Confirm New Password:</label>
       <input class="form-control" type="password" name="new_password_confirmation" id="confirm_new_password">
       <span class="text-danger">{{ $errors->first('new_password_confirmation') }}</span>
     </div> 
    <div>Change profile image:
     <br>
     <br>

    </div>
     <div class="input-group mb-3">
       <div class="input-group-prepend">
         <span class="input-group-text" id="inputGroupFileAddon01">Upload</span>
       </div>
       <div class="custom-file">
         <input name="image" type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
         <label class="custom-file-label" for="inputGroupFile01">profile image</label>
       </div>
     </div>

     <div class="form-group">
         <small class="text-muted">The Image must be: jpg,jpeg,png,gif with max size: 5mb</small><br>
         <span class="text-danger">{{ $errors->first('image') }}</span>
     </div>

     <input name="submit" class="btn btn-primary btn-block" type="submit" value="Change information">    
   </form> 
 </div> 
</div>

What am I doing wrong?

May
06
3 weeks ago
Activity icon

Replied to Validating Unique Form Exception

Thank you all for your help

I found a creative way around my issue I saved the email address in a session.

This is my code and it works

  'email' => 'required|email|unique:users,email,'.Session::get('user_id'),    

A special thank you to @MichalOravec for his help he you it again

Activity icon

Replied to Validating Unique Form Exception

@MichalOravec

Yes I use FormRequest right

I do not understand your other answers.

Activity icon

Replied to Validating Unique Form Exception

@MichalOravec I tried your suggestion

and got the following error

“Trying to get property of non-object”

I also tried

 email' => 'required|email|unique:users,email,'.$this->user()->email

and got the same error.

Please advise

Activity icon

Replied to Validating Unique Form Exception

@MichalOravec

I am Not sure what you mean by change your route

This is my route


Route::post('edit', '[email protected]');

What do I do now?

Activity icon

Started a new Conversation Validating Unique Form Exception

I have the following form validation

return [
            'name' => 'required|min:2|max:50',            
            'email' => 'required|email|unique:users,email',                      
            'new_password' => 'required|min:6|max:20|confirmed'
           
        //
    
    ];

The form is a form that allows a user to update their profile information.

For the



'email' => 'required|email|unique:users,email',

It checks the email address against the database and requires it to be unique however I want to make one exception which is if it is this particular user email address that he will not have to change it. That way I do not force him to change his email address.

I tried the following variations with no success


'email' => 'required|email|unique:users,email,' .$this->$content['email'],

'email' => 'required|email|unique:users,email,'.$email->id,

However both of them seem not to be working What am I doing wrong?

Activity icon

Replied to Check Passwords That They Are Identical In Request Confirmed

@MichalOravec

Your answer is awesome

And I really debating what answer to pick.

However the main question was regarding password_confirmation

After I read his answer I knew what to do. I wish I can pick 2 best answer for this question.

Activity icon

Replied to Check Passwords That They Are Identical In Request Confirmed

@wingly and @MichalOravec thank you for clarifying regarding the confirmation

Regarding customizing the message. I tried your suggestion however it does not work.

This is my code


class EditProfileRequest extends FormRequest
{

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        
        $user_email = Session::get('user_email');
        return [
            'name' => 'required|min:2|max:50',            
            'email' => 'required|email|unique:users,email',
            'new_password' => 'required|min:6|max:20|',            
            'confirm_new_password' => 'required|min:6|max:20|confirmed',
        //
    
    ];
    }

    public function messages()
{
    return [
        'new_password.confirmed' => 'Your new password and new password confirmation must be the same',
    ];
}

    
}

I only want customize part of the message not all of it how to override part of it?

Activity icon

Replied to Check Passwords That They Are Identical In Request Confirmed

Your solution works however, I don’t understand how it knows that new_password and new_password_confirmation

What actually ties them in together?

Also when I try to submit on purpose on the form wrong information I get the following error message

“The confirm new password field is required.”

I would like to customize the error message that it will say “Your new password and new password confirmation must be the same”

How can I customize the message?

This my form code:

 <div class="form-group">
        <label for="confirm-password">*New Password:</label>
        <input class="form-control" type="password" name="new_password" id="new_password">
        <span class="text-danger">{{ $errors->first('new_password') }}</span>
      </div>   

      <div class="form-group">
        <label for="confirm-password">*Confirm New Password:</label>
        <input class="form-control" type="password" name="confirm_new_password" id="confirm_new_password">
        <span class="text-danger">{{ $errors->first('confirm_new_password') }}</span>
      </div>

Activity icon

Started a new Conversation Check Passwords That They Are Identical In Request Confirmed

I am trying to build a request

I want to make sure that the request checks that 'new_password' & 'confirm_new_password' are identical how can this be done?

This is my code

return [
            'name' => 'required|min:2|max:50',
            'email' => 'required|email|unique:users,email',
            'new_password' => 'required|min:6|max:20|confirmed',
            'confirm_new_password' => 'required|min:6|max:20|confirmed',
        ];


May
04
4 weeks ago
Activity icon

Started a new Conversation Serialize Array

I have the following array in $temp with has on array with the key “data”

The information in “data” is serialize.

When i do in my controller dd($temp);

I get

array:2 [▼
  0 => {#280 ▼
    +"name": "avi"
    +"id": 10
    +"user_id": 1
    +"data": """
      a:3:{i:5;a:6:{s:2:"id";s:1:"5";s:4:"name";s:111:"14k Yellow Gold Round Classic Yellow Solitaire Diamond Stud Earrings (0.75 Ct, Fancy Yellow(Irradiated), SI )\r ▶
      ";s:5:"price";d:2344;s:8:"quantity";i:1;s:10:"attributes";a:0:{}s:10:"conditions";a:0:{}}i:9;a:6:{s:2:"id";s:1:"9";s:4:"name";s:107:"18k White Gold Princess Inv ▶
      ";s:5:"price";d:600;s:8:"quantity";i:1;s:10:"attributes";a:0:{}s:10:"conditions";a:0:{}}i:8;a:6:{s:2:"id";s:1:"8";s:4:"name";s:98:"18k White Gold Invisible Sett ▶
      ";s:5:"price";d:9000;s:8:"quantity";i:1;s:10:"attributes";a:0:{}s:10:"conditions";a:0:{}}}
      """
    +"total": 11944
    +"created_at": "2020-05-03 09:36:50"
    +"updated_at": "2020-05-03 09:36:50"
  }
  1 => {#273 ▼
    +"name": "avi"
    +"id": 11
    +"user_id": 1
    +"data": """
      a:4:{i:1;a:6:{s:2:"id";s:1:"1";s:4:"name";s:92:"18k White Gold Round Cut Multi-stone Diamond Eternity Band (0.32 Ct, G Color, SI2 Clarity)

      ";s:5:"price";d:1002;s:8:"quantity";i:1;s:10:"attributes";a:0:{}s:10:"conditions";a:0:{}}i:2;a:6:{s:2:"id";s:1:"2";s:4:"name";s:111:"18k Yellow Gold Princess Cu ▶
      ";s:5:"price";d:1222;s:8:"quantity";i:1;s:10:"attributes";a:0:{}s:10:"conditions";a:0:{}}i:5;a:6:{s:2:"id";s:1:"5";s:4:"name";s:111:"14k Yellow Gold Round Class ▶
      ";s:5:"price";d:2344;s:8:"quantity";i:1;s:10:"attributes";a:0:{}s:10:"conditions";a:0:{}}i:13;a:6:{s:2:"id";s:2:"13";s:4:"name";s:80:"18k White Gold Round Cut D ▶
      """
    +"total": 6168
    +"created_at": "2020-05-03 09:58:43"
    +"updated_at": "2020-05-03 09:58:43"
  }
]

When I use

  dd(unserialize($temp[0]->data));

I get

array:3 [▼
  5 => array:6 [▼
    "id" => "5"
    "name" => "14k Yellow Gold Round Classic Yellow Solitaire Diamond Stud Earrings (0.75 Ct, Fancy Yellow(Irradiated), SI )
"
    "price" => 2344.0
    "quantity" => 1
    "attributes" => []
    "conditions" => []
  ]
  9 => array:6 [▼
    "id" => "9"
    "name" => "18k White Gold Princess Invisible Setting heart elegant modern classic diamond pendant (1.01 Ct, H , VS )
"
    "price" => 600.0
    "quantity" => 1
    "attributes" => []
    "conditions" => []
  ]
  8 => array:6 [▼
    "id" => "8"
    "name" => "18k White Gold Invisible Setting Pear Cut Diamond Flower Pendant (0.57 Ct, G Color, SI1 Clarity)
"
    "price" => 9000.0
    "quantity" => 1
    "attributes" => []
    "conditions" => []
  ]
]

How can I create an array that has a sentence with 2 part information? for example:

Id:5,name: 14k Yellow Gold Round Classic Yellow Solitaire Diamond Stud Earrings (0.75 Ct, Fancy Yellow(Irradiated), SI ) Price: 2344 Quantity:1

Id:9,name: 18k White Gold Princess Invisible Setting heart elegant modern classic diamond pendant (1.01 Ct, H , VS ) Price: 600.0 Quantity:1

Thank you for your help

Activity icon

Replied to Unserialize In Blade

It seems there was a typo is the for each loop

It needs to be

@foreach (unserialize($val->data) as $item)

Thank you for your help

Activity icon

Replied to Unserialize In Blade

@MichalOravec

It is still not working

I am getting the following error

“Undefined offset: 1”

This is my code

<tbody>
      
    
      @if(!empty($content)) 
        @foreach($content as $val)
          

  
        
       
          <tr>
          <td>{{$val->id}}</td>       
          <td>{{ App\Custom_class\Helper::convertDates($val->created_at)}}</td>
          <td>{{$val->name}}</td> 
          <td>Order Information</td>        
          @foreach (unserialize($val->data) $as item)
          {{ $item['id'] }}
      
      @endforeach        
           <td>${{number_format($val->total)}}</td> 
         
 
            
                     
            
         </tr>

      @endforeach   
    @endif

    </tbody>
Activity icon

Replied to Unserialize In Blade

@MichalOravec

This the code from my blade template


 <tbody>
      
    
      @if(!empty($content)) 
        @foreach($content as $val)
          

        {{var_dump(unserialize($val->data))}}
        
       
          <tr>
          <td>{{$val->id}}</td>       
          <td>{{ App\Custom_class\Helper::convertDates($val->created_at)}}</td>
          <td>{{$val->name}}</td> 
          <td>Order Information</td>        
          {{-- <td>{{ unserialize($val['data'])[0]->name }}</td> --}}          
           <td>${{number_format($val->total)}}</td> 
         

            
                     
            
         </tr>

      @endforeach   
    @endif

    </tbody>

Everything is working great except for

{{ unserialize($val['data'])[0]->name }}

Which is currently on a remark

When I use


{{var_dump(unserialize($val->data))}}

I get

array(3) { [5]=> array(6) { ["id"]=> string(1) "5" ["name"]=> string(111) "14k Yellow Gold Round Classic Yellow Solitaire Diamond Stud Earrings (0.75 Ct, Fancy Yellow(Irradiated), SI ) " ["price"]=> float(2344) ["quantity"]=> int(1) ["attributes"]=> array(0) { } ["conditions"]=> array(0) { } } [9]=> array(6) { ["id"]=> string(1) "9" ["name"]=> string(107) "18k White Gold Princess Invisible Setting heart elegant modern classic diamond pendant (1.01 Ct, H , VS ) " ["price"]=> float(600) ["quantity"]=> int(1) ["attributes"]=> array(0) { } ["conditions"]=> array(0) { } } [8]=> array(6) { ["id"]=> string(1) "8" ["name"]=> string(98) "18k White Gold Invisible Setting Pear Cut Diamond Flower Pendant (0.57 Ct, G Color, SI1 Clarity) " ["price"]=> float(9000) ["quantity"]=> int(1) ["attributes"]=> array(0) { } ["conditions"]=> array(0) { } } } array(4) { [1]=> array(6) { ["id"]=> string(1) "1" ["name"]=> string(92) "18k White Gold Round Cut Multi-stone Diamond Eternity Band (0.32 Ct, G Color, SI2 Clarity) " ["price"]=> float(1002) ["quantity"]=> int(1) ["attributes"]=> array(0) { } ["conditions"]=> array(0) { } } [2]=> array(6) { ["id"]=> string(1) "2" ["name"]=> string(111) "18k Yellow Gold Princess Cut Modern classic four stone diamond engagement ring (0.42 Ct, H Color, VS Clarity) " ["price"]=> float(1222) ["quantity"]=> int(1) ["attributes"]=> array(0) { } ["conditions"]=> array(0) { } } [5]=> array(6) { ["id"]=> string(1) "5" ["name"]=> string(111) "14k Yellow Gold Round Classic Yellow Solitaire Diamond Stud Earrings (0.75 Ct, Fancy Yellow(Irradiated), SI ) " ["price"]=> float(2344) ["quantity"]=> int(1) ["attributes"]=> array(0) { } ["conditions"]=> array(0) { } } [13]=> array(6) { ["id"]=> string(2) "13" ["name"]=> string(80) "18k White Gold Round Cut Diamond Bangle Bracelet (0.75 Ct, G Color, VS1 Clarity)" ["price"]=> float(1600) ["quantity"]=> int(1) ["attributes"]=> array(0) { } ["conditions"]=> array(0) { } } } array(2) { [5]=> array(6) { ["id"]=> string(1) "5" ["name"]=> string(111) "14k Yellow Gold Round Classic Yellow Solitaire Diamond Stud Earrings (0.75 Ct, Fancy Yellow(Irradiated), SI ) " ["price"]=> float(2344) ["quantity"]=> int(1) ["attributes"]=> array(0) { } ["conditions"]=> array(0) { } } [6]=> array(6) { ["id"]=> string(1) "6" ["name"]=> string(137) "18k White Gold Invisible Setting Round Cut Diamond Flower Earrings (0.77 Ct, G Color with Surrounding Blue Sapphire Stones, VS Clarity) " ["price"]=> float(1500) ["quantity"]=> int(1) ["attributes"]=> array(0) { } ["conditions"]=> array(0) { } } }

Please advise what I’m doing wrong

Activity icon

Replied to Unserialize In Blade

@MichalOravec I tried your suggestion and got the following error:

“Undefined offset: 0 (0)”

Any other ideas?

Activity icon

Started a new Conversation Unserialize In Blade

I have the following information in my database which is decoded with Serialize

This is what I have saved


a:3:{i:5;a:6:{s:2:"id";s:1:"5";s:4:"name";s:111:"14k Yellow Gold Round Classic Yellow Solitaire Diamond Stud Earrings (0.75 Ct, Fancy Yellow(Irradiated), SI )
";s:5:"price";d:2344;s:8:"quantity";i:1;s:10:"attributes";a:0:{}s:10:"conditions";a:0:{}}i:9;a:6:{s:2:"id";s:1:"9";s:4:"name";s:107:"18k White Gold Princess Invisible Setting heart elegant modern classic diamond pendant (1.01 Ct, H , VS )
";s:5:"price";d:600;s:8:"quantity";i:1;s:10:"attributes";a:0:{}s:10:"conditions";a:0:{}}i:8;a:6:{s:2:"id";s:1:"8";s:4:"name";s:98:"18k White Gold Invisible Setting Pear Cut Diamond Flower Pendant (0.57 Ct, G Color, SI1 Clarity)
";s:5:"price";d:9000;s:8:"quantity";i:1;s:10:"attributes";a:0:{}s:10:"conditions";a:0:{}}}

When I try to use the following command

 <td>{{unserialize($val['data'])}}</td> 

In my blade template I get the following error:

htmlspecialchars() expects parameter 1 to be string, array given (

What am I doing wrong?

May
03
4 weeks ago
Activity icon

Replied to Dd Not Printing Multidimensional Array

@mvd Thank you that works!!!

Activity icon

Started a new Conversation Dd Not Printing Multidimensional Array

I have the following method

 static public function delete_category($id)

 {
    $product =  Self::find($id)->toArray();
    

    $query = "SELECT id from products WHERE category_id = {$id}"; 
    $all_products_id = DB::select($query);

   
   
    dd($all_products_id[0]["id"]);
    product::delete_product($all_products_id[0]); 
   

 
 }

When I try the dd($all_products_id[0]["id"]); I get the following error “Cannot use object of type stdClass as array”

My array structure is

array:5 [▼ 0 => {#240 ▼ +"id": 22 }

1 => {#244 ▼ +"id": 24 }

2 => {#246 ▶} 3 => {#247 ▶} 4 => {#252 ▶} ]

Why am I getting this error? What am I doing wrong?

Apr
27
1 month ago
Activity icon

Replied to Get Rid Of Time In A Date In Blade

@Snapey

Thank you that works. I learned a lot.

Is there a way to make it more elegant than writing that full namespace in the ?

Activity icon

Replied to Get Rid Of Time In A Date In Blade

@jlrdw

What do you mean by “Try using the full namespace.”

Where to use this full namespace? In the Blade template?

are in the ? Can you explain more?

Activity icon

Replied to Get Rid Of Time In A Date In Blade

@jlrdw

Your changes worked Thank you!!!! however if you want to use them directly on the blade template for example

{{ Helper::convertDates($val['created_at'])}}

That does not work

Not sure how do I do use for a blade template

Activity icon

Replied to Get Rid Of Time In A Date In Blade

Yes,

This what I have

use App\Custom_class\Helper;
Activity icon

Replied to Get Rid Of Time In A Date In Blade

@jlrdw @tykus @a4ashraf

I built my first ever custom class

However when I tried to run the code I get following error

“Class 'app\Custom_class\Helper' not found”

In my controller I tried just to convert one date and see how it works. And If it works to build a forEach loop to take care of the rest: // this is where the debuuger tells me it is problematic.

$temp = Helper::convertDates($temp); 

This is my custom made class

<?php

namespace App\Custom_class;
 
class Helper

{

static public function convertDates($date)
{

  $createDate = new DateTime($date);

    $strip = $createDate->format('d-m-Y');
    return $strip;
    
 
 
}

}

This is the controller class using the custom made class

    public function index()
    {
        $data['content'] = product::all()->toArray();  
    
        $temp = Helper::convertDates($temp);
        

        dd($temp);
        // dd( $data['content']);
        // dd($data['content'][0]['created_at']);

        return view('cms.content.cms_products',$data);

    }

What am I doing wrong?

Apr
26
1 month ago
Activity icon

Replied to Get Rid Of Time In A Date In Blade

@a4ashraf What would be best practice to import Carbon to my controller and change the information there before I import the information to my view?