Edris899

Edris899

Member Since 11 Months Ago

Experience Points 920
Experience Level 1

4,080 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-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.

10 Sep
11 months ago

Edris899 left a reply on How To Use Factory To Generate Data With Different Models?

Answer to Question 1, 2 & 3

<?php

use Faker\Generator as Faker;

use App\Photo;
$factory->define(App\Photo::class, function (Faker $faker) {
    
    $imageDownload = $faker->image(storage_path('app/public/user-content'),
    720,480);
    
    $imagePath = explode('\', $imageDownload);
    $imageName = end($imagePath);
    return [
        'user_id'       =>  2,  
        'title'         =>  $faker->word,
        'description'   => $faker->sentence(),
        'photo'         => $imageName,
        'processed'     => $faker->dateTime($timezone = null),
    ];
});

$factory->afterCreating(App\Photo::class, function ($photo, $faker) {
    $photo->albums()->save(
        factory('App\Album')->create()
    );
    $photo->attachCategories(rand(1,9));
});

Edris899 started a new conversation How To Use Factory To Generate Data With Different Models?

Hi there,

Using Laravel 5.6.

I am making a illustration & album website. And I have already generated with factory some albums.

I have a couple of questions.

Question 1 How can I generate photos that are linked to those generated albums at that specific time. I know how to generate it separately but this one I don't know. I have already a photo model etc.

Question 2 I am using a categories package for laravel, is there also a way to give each generated photo a random categorie?

Question 3 Is is possible to give each photos src a random link to a dummy picture? And how?

Thanks in advance

This is the faker code for the album.

<?php

use Faker\Generator as Faker;

$factory->define(App\Album::class, function (Faker $faker) {
    return [
        'name'          => $faker->word,
        'description'   => $faker->sentence(),
        'user_id'       => 2,
    ];
});

This is the faker code for the photo.

<?php

use Faker\Generator as Faker;

$factory->define(App\Photo::class, function (Faker $faker) {
    return [
        'user_id'       =>  2,  
        'title'         =>  $faker->word,
        'description'   => $faker->sentence(),
        

    ];
});
04 Sep
11 months ago

Edris899 left a reply on How To Check If Uploaded Image Has A Watermark?

Hi @Cronix I understand. I just don't want users to upload licensed images. Is there a way to check for a license? I read something about meta?

Edris899 started a new conversation How To Check If Uploaded Image Has A Watermark?

Hi there,

I am building a illustration & album website with Laravel 5.6. I was wondering if there is a way to check if a uploaded image has a watermark on it and do actions based upon the outcome. Because the main problem is that I don't wan't to have people uploading images that are licensed or have a watermark on it.

Any ideas?

Edris899 left a reply on The Path Is Not Writeable Using Chumper\Zipper Error?

To help the community I will answer my own question.

For me the following command fixed the problem. sudo chmod a+rw -R public/

This is the controller code I used.

if(!file_exists('public/testZipFolder/')){
        Storage::makeDirectory('public/testZipFolder/',0644,true);
    }
    $zipper = new \Chumper\Zipper\Zipper;
    $zipper->make(public_path('storage/testZipFolder/test.zip'))->folder('test')->add(public_path('storage/user-content'));
    $zipper->zip(public_path('storage/testZipFolder/test.zip'))->folder('test')->add('storage/user-content','test');
    $zipper->close();
    return response()->download('storage/testZipFolder/test.zip')->deleteFileAfterSend(false);
}

Edris899 started a new conversation The Path Is Not Writeable Using Chumper\Zipper Error?

Hi there,

Using:

Laravel 5.6 Ubuntu 17.xx LTS

I am trying to test a Laravel 5 package called Chumper\Zipper. The idea is to zip selected photos and download it.

But to test it first I got this example from there github page. But it's throwing me a error the the path is not writeable.

Which path? And how to fix? Any ideas?

The error.

The path "test.zip" is not writeable

This is the controller code.

 public function zipPhotos(Request $request){

        $zipper = new \Chumper\Zipper\Zipper;
        $zipper->make('test.zip')->folder('test')->add('composer.json');
        $zipper->zip('test.zip')->folder('test')->add('composer.json','test');
        $zipper->remove('composer.lock');

        $zipper->folder('mySuperPackage')->add(
            array(
                'vendor',
                'composer.json'
            )
        );
        $zipper->getFileContent('mySuperPackage/composer.json');
        $zipper->make('test.zip')->extractTo('',array('mySuperPackage/composer.json'),Zipper::WHITELIST);
        $zipper->close();
        

        return response()->download('test.zip')->deleteFileAfterSend(true);

    }

This is the route.

Route::get('zipPhotos', '[email protected]')->name('zipPhotos');

Thanks in advance.

Edris899 left a reply on Can I Zip Or Rar Images Without A Package?

@bobbybouwmann Thanks. You know if it would affect performance? Like server performance? Say there are 1000 people at the same time downloading a zip, would be better to use plain php or a laravel package? In terms of performance and fast reload times

Edris899 left a reply on Can I Zip Or Rar Images Without A Package?

@bobbybouwmann Aright thanks alot. I was just wondering what is the best way using laravel package or ziparchive. Any ideas?

Edris899 started a new conversation Can I Zip Or Rar Images Without A Package?

Hi there,

I am trying to Zip or Rar my selected images and force a download. I have googled on the internet and there is a package called chumper/zipper that is used alot.

Is there a way to use only laravel 5.6 to do this?

Apparently there is a class called ZipArchive?

Thanks in advance

02 Sep
11 months ago

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

Getting also data with the photo_id

{success: true, album_id: "52", photo_id: Array(2)}
album_id
:
"52"
photo_id
:
(2) ["32", "33"]
success
:
true

So I think @Cronix it works? :D

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

I changed

url: '/users/photos/movePhotosToAlbumAjax/',

To this

url: '/users/photos/movePhotosToAlbumAjax',

In the controller I used this.

public function movePhotosToAlbumAjax(Request $request){
        $request->photo_id; // array of all selected photo id's
        $album_id = $request->album_id; // id of album
        
        return ['success' => true,'album_id' => $album_id];
    }

Getting the following results in the console after clicking on submit.

{success: true, album_id: "52"}

So I thinks it works?

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

The route is already post.

    Route::post('users/photos/movePhotosToAlbumAjax/','[email protected]')->name('users.photos.movePhotosToAlbumAjax');

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

Yes I do indeed have that in the html<head> Hmm yeah thats so weird haha :P Running on ubuntu apache2

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

No.I think no token in the html?

The javascript.

<script type="text/javascript">
     $("#myform").on("submit", function(e) {
            e.preventDefault(); // prevent the form submission
            console.log("benaan");
            
            $.ajax({
                type: "post",
                dataType: 'JSON',
                url: '/users/photos/movePhotosToAlbumAjax/',
                data: $('#myform').serialize(), // serialize all form inputs
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
                success: function(response) {
                    console.log("de response terug");
                    console.log(response);
                },
                error: function(data) {
                    console.log(data)
                }
            });
        });
</script>

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

@Cronix getting the following error in the console of chrome.

GET http://www.test.nl.test/users/photos/movePhotosToAlbumAjax 405 (Method Not Allowed)

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

@Cronix thanks I am trying it right now.

@jlrdw thanks for the reply and the tips will do.

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

Aright i have copied some html to the modal where the form is. To select there the photo(s) to move and to select the album.

This is the whole view file.

@extends('layouts.app') 
@section('content')
<br>
<div class="container-fluid">
   <div class="row">
      <div class="col-lg-12">
         <div class="jumbotron jumbotron-fluid">
            <div class="row text-center">
               <div class="col-lg-6 offset-lg-3">
                  <h4>Album: {{$album->name}}</h4>
               </div>
            </div>
            <br>
            <div class="row">
               <div class="col-md-2 offset-md-1">
                  <a class="btn btn-secondary" href="{{route('users.photos.home')}}" role="button">Go Back</a>
               </div>
               <div class="col-lg-6 offset-lg-0">
                  <div class="input-group input-group-lg mb-3" style="margint-top:-30px;">
                     <input type="text" class="form-control" placeholder="Search your illustrations" aria-label="Search your illustrations" aria-describedby="button-addon2">
                     <div class="input-group-append">
                        <button class="btn btn-outline-secondary" type="button" id="button-addon2">Search</button>
                     </div>
                  </div>
               </div>
            </div>
            <br>
            <div class="row">
               <div class="col-lg-8 offset-lg-3">
                  <button class='btn btn disabled' style='background-color:#cfd8dc;'>
                  <i class="fa fa-user-friends grayText"></i> Share
                  </button>
                  <button class='btn btn' style='background-color:#cfd8dc;'>
                  <i class="fas fa-check-double grayText"></i> Select All
                  </button>
                  <button class='btn btn' style='background-color:#cfd8dc;' data-toggle="modal" data-target="#addIllustration">
                  <i class="fas fa-images grayText"></i> Add Illustration
                  </button>
                  <button class='btn btn moveIllustration' style='background-color:#cfd8dc;' data-toggle="modal" data-target=".bd-example-modal-lg">
                  <i class="fas fa-images grayText"></i> Move Illustration
                  </button>
                  <button class='btn btn' style='background-color:#cfd8dc;' id="delete" type="submit" data-token="{{ csrf_token() }}">
                  <i class="fas fa-trash grayText"></i>
                  </button>
                  @if($photosProcessedCount == 1 )
                  <h5 class="grayText float-right">{{$photosProcessedCount}} Illustration Found</h5>
                  @else
                  <h5 class="grayText float-right">{{$photosProcessedCount}} Illustrations Found</h5>
                  @endif
               </div>
            </div>
            <div class="row">
               <div class="col-lg-8 offset-lg-3">
                  <h5 class="grayText float-right">{{$photosProcessedCount}}  Processed</h5>
               </div>
            </div>
            <div class="row">
               <div class="col-lg-8 offset-lg-3">
                  <h5 class="grayText float-right">{{$photosNotProcessedCount}} Not Processed</h5>
               </div>
            </div>
            @if($photosNotProcessedCount != 0)
            <div class="row text-center">
               <div class="col-lg-6 offset-lg-3">
                  <i class="fas fa-exclamation fa-2x"></i>
                  <h5>You have illustrations to be processed.</h5>
               </div>
            </div>
            <div class="row text-center">
               <div class="col-lg-6 offset-lg-3">
                  <a name="" id="" class="btn btn-success" href="{{route('users.photos.viewNonProcessed',$album->id)}}" role="button">Process Illustrations</a>
               </div>
            </div>
            @endif
            <div class="row">
               <div class="col-lg-6 offset-lg-3">
                  <hr>
               </div>
            </div>
            <br>
            <div class="row">
               @foreach($photosProcessed as $photoProcessed)
               <div class="col-lg-2" id="photo-{{ $photoProcessed->id }}">
                  <div class="content" id="content" >
                     <a id="overlay" href="{{route('users.photos.show',$photoProcessed->id)}}">
                        <div class="content-overlay">
                           <div class="col-lg-2">
                              <label class="checkbox_custom">
                              <input type="checkbox" name="checkbox_custom_a" id="{{$photoProcessed->id}}">
                              <span class="checkmark"></span>
                              </label>
                           </div>
                        </div>
                        <img class="content-image" src="#" alt="{{$photoProcessed->title}}">
                        <div class="content-details fadeIn-bottom">
                           <h3 class="content-title">{{$photoProcessed->title}}</h3>
                           <p class="content-text">{{$photoProcessed->description}}</p>
                        </div>
                     </a>
                  </div>
                  <br>
               </div>
               @endforeach
            </div>
         </div>
      </div>
   </div>
</div>
<div class="modal fade" id="addIllustration" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
   <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
         <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">Add Illustrations</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
            </button>
         </div>
         <div class="modal-body">
            <div class="row">
               <div class="col-lg-12">
                  <div id="image_preview"></div>
                  <br>
                  <form action="{{ route('users.photos.storePhotosToAlbum', $album->id) }}" method="post" enctype="multipart/form-data">
                     {{ csrf_field() }}
                     <input type="file" id="uploadFile" name="uploadFile[]" multiple/>
                     <input type="submit" class="btn btn-success" name='submitImage' value="Upload Image"/>
                  </form>
                  <br/>
               </div>
            </div>
         </div>
      </div>
   </div>
</div>
//This is the modal for the movePhotosToAlbum
<div class="modal fade bd-example-modal-lg" id="moveIllustration" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
   <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
      <div class="modal-content">
         <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">Move Illustrations</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
            </button>
         </div>
         <div class="modal-body">
            <div class="row">
               <div class="col-lg-12">
                  <form data-toggle="validator" action="{{route('users.photos.movePhotosToAlbumAjax')}}" method="post">
                     {{method_field('POST')}}
                     @csrf
                     <div class="form-group">
                        @foreach($photosProcessed as $photoProcessed)
                        <div class="col-lg-4" id="photo-{{ $photoProcessed->id }}">
                           <div class="content" id="content" >
                              <a id="overlay" href="{{route('users.photos.show',$photoProcessed->id)}}">
                                 <div class="content-overlay">
                                    <div class="col-lg-2">
                                       <label class="checkbox_custom">
                                       <input type="checkbox" name="checkbox_custom_a[]" value="{{$photoProcessed->id}}">
                                       <span class="checkmark"></span>
                                       </label>
                                    </div>
                                 </div>
                                 <img class="content-image" src="#" alt="{{$photoProcessed->title}}">
                                 <div class="content-details fadeIn-bottom">
                                    <h3 class="content-title">{{$photoProcessed->title}}</h3>
                                    <p class="content-text">{{$photoProcessed->description}}</p>
                                 </div>
                              </a>
                           </div>
                           <br>
                        </div>
                        @endforeach
                     </div>
                     <div class="form-group">
                        <label for="exampleFormControlSelect1">Choose a album</label>
                        <select class="form-control" id="chosenAlbum">
                           @foreach($albums as $album)
                           <option id="{{$album->id}}" value="{{$album->id}}">{{$album->name}}</option>
                           @endforeach
                        </select>
                     </div>
                     <div class="row text-center">
                        <div class="col-lg-6 offset-lg-3">
                           <input data-token="{{ csrf_token() }}" id="moveIllustrationSubmit" type="submit" class="btn btn-success" value="Move Illustration"/>
                        </div>
                     </div>
                  </form>
                  <br/>
               </div>
            </div>
         </div>
      </div>
   </div>
</div>
</div>
@endsection
@section('scripts')
<script type="text/javascript">
   $( document ).ready(function() {
       $('.moveIllustration').addClass('disabled');
   
       
       $( "input" ).change(function() {
           var $input = $( this );
           var checkboxState = $input.prop("checked");
   
           if(checkboxState == true){
               $(this).closest(".content").addClass("checked details");
               //$(this).find("#moveIllustration").removeClass("disabled");
               $('.moveIllustration').removeClass('disabled');
           }
   
           if(checkboxState == false){
               $(this).closest(".content").removeClass("checked details");
               $('.moveIllustration').addClass('disabled');
   
           }
       }).change();
   
   
       //$("#chosenAlbum").change(function() {
       //    var albumId = $(this).find('option:selected').attr('id');
       //    console.log(albumId);
       //  });
   
       
       $( "#moveIllustrationSubmit" ).on( "click", function(e) {
           e.preventDefault(); // prevent the form submission
           $("input:checkbox:checked").each(function () {
               var $input = $( this );
               var photo_id = $input.attr("id");
               console.log("benaan0");
               //console.log("Id: " + $input.attr("id") + " Value: " + $input.val());
               $("#chosenAlbum").change(function() {
                   //var albumId = $(this).find('option:selected').attr('id');
                   var albumId = $(this).val();
                   console.log('benaan');
                   
                   //var albumId = $("#chosenAlbum").find('option:selected').attr('id');
                   $.ajax({
                       type: "post",
                       dataType: 'JSON',
                       url: '/users/photos/movePhotosToAlbumAjax/',
                       data: {},
                       headers: {
                           'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                       },
                       success: function (response) {
                           console.log("de response terug");
                           console.log(response);
                           //$('#photo-' + url_id).remove();
                       
                       },
                       error: function (data) {
                           console.log(data)
                       }
                   });
             });
           });
       });
       
   
   
   
   
   
   
       $( "#delete" ).on( "click", function() {
           var confirmation = confirm("Are you sure you want to remove the Illustration(s)?");
   
           if (confirmation)  {
               $("input:checkbox:checked").each(function () {
                   var $input = $( this );
                   //console.log("Id: " + $input.attr("id") + " Value: " + $input.val());
                   
                   var _id = $input.attr("id");
                   
                   
                   $.ajax({
                       type: "post",
                       url: '/users/photos/destroy/' + url_id,
                       data: {"id": url_id , _method: 'delete'},
                       headers: {
                           'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                       },
                       success: function () {
                           
                           $('#photo-' + url_id).remove();
                       
                       },
                       error: function (data) {
                           //console.log('Error:', data);
                       }
                   });
               });
           }
       });
   
       
   });
   
   
</script>
@endsection

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

Yeah. I understand. I am trying to make something in that model aka form. To select there the photo(s) and the album.

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

Hmm oke oke. So you mean to rearrange the html?

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

Sorry the checkboxes are used by this html.

<div class="row">
   @foreach($photosProcessed as $photoProcessed)
   <div class="col-lg-2" id="photo-{{ $photoProcessed->id }}">
      <div class="content" id="content" >
         <a id="overlay" href="{{route('users.photos.show',$photoProcessed->id)}}">
            <div class="content-overlay">
               <div class="col-lg-2">
                  <label class="checkbox_custom">
                  <input type="checkbox" name="checkbox_custom_a" id="{{$photoProcessed->id}}">
                  <span class="checkmark"></span>
                  </label>
               </div>
            </div>
            <img class="content-image" src="/storage/user-content/{{$user->hash}}/{{$photoProcessed->hash}}/{{$photoProcessed->thumbnailhash}}/{{$photoProcessed->photo}}" alt="{{$photoProcessed->title}}">
            <div class="content-details fadeIn-bottom">
               <h3 class="content-title">{{$photoProcessed->title}}</h3>
               <p class="content-text">{{$photoProcessed->description}}</p>
            </div>
         </a>
      </div>
      <br>
   </div>
   @endforeach
</div>

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

Hahah Cronix I am trying bro, I am trying . Well the idea behind is to check which photos is checked en get those ids. So if 2 photos are checked then it should move those 2 to the selected album from the selection menu/option.

Edris899 left a reply on How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

Hi @Cronix

I changed the javascript code and code in the controller. But now it doesn't submit the form after clicking. Nothing happens.

This is the jquery.

  $("#moveIllustrationSubmit").on("click", function(e) {
     e.preventDefault(); // prevent the form submission
     $("input:checkbox:checked").each(function() {
         var $input = $(this);
         var photo_id = $input.attr("id");

         $("#chosenAlbum").change(function() {

             var albumId = $(this).val(); // just use the value of the selected element


             $.ajax({
                 type: "post",
                 dataType: 'JSON',
                 url: '/users/photos/movePhotosToAlbumAjax/',
                 data: {
                     "photo_id": photo_id,
                     "albumId": albumId
                 },
                 headers: {
                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                 },
                 success: function(response) {
                     console.log("de response terug");
                     console.log(response);
                     //$('#photo-' + url_id).remove();

                 },
                 error: function(data) {
                     console.log(data)
                 }
             });
         });
     });
 });

About the data. I need the photo id thats selected and the selected newalbum id. Those I need to get transfered via ajax.

Edris899 started a new conversation How To Fetch Data From A Ajax Post Request In The Controller? Getting No Data

Hi there,

I am building a illustration & album website in Laravel 5.6. I want to move a picture from a album to a different album with ajax.

The idea is to first select a picture with a checkbox on it. Then click on a button that toggles a bootstrap modal popup. Choosing the or selecting 1 album to move to. Then hitting the submit button.

The problem is that I don't get the data from the jquery ajax request. Only getting this response back

array:2 [▼
  "_method" => "POST"
  "_token" => "PURBuZhwRdDqMoVAQwoseoZsffQC2e6N2DDqpiYB"
]

This is the html code.

<form data-toggle="validator" action="{{route('users.photos.movePhotosToAlbumAjax')}}" method="post">
   {{method_field('POST')}}
   @csrf
   <div class="form-group">
      <label for="exampleFormControlSelect1">Choose a album</label>
      <select class="form-control" id="chosenAlbum">
         @foreach($albums as $album)
         <option id="{{$album->id}}" value="{{$album->id}}">{{$album->name}}</option>
         @endforeach
      </select>
   </div>
   <div class="row text-center">
      <div class="col-lg-6 offset-lg-3">
         <input data-token="{{ csrf_token() }}" id="moveIllustrationSubmit" type="submit" class="btn btn-success" value="Move Illustration"/>
      </div>
   </div>
</form>

This is the code in the controller.

public function movePhotosToAlbumAjax(Request $request){
        $data = $request->all();
        dd($data);
        return response()->json(['success'=>'Got Simple Ajax Request.']);;
    }

And this is the jquery.

$("#moveIllustrationSubmit").on("click", function() {
    $("input:checkbox:checked").each(function() {
        var $input = $(this);
        var photo_id = $input.attr("id");
        //console.log("Id: " + $input.attr("id") + " Value: " + $input.val());
        $("#chosenAlbum").change(function() {
            var albumId = $(this).find('option:selected').attr('id');

            //var albumId = $("#chosenAlbum").find('option:selected').attr('id');
            $.ajax({
                type: "post",
                dataType: 'JSON',
                url: '/users/photos/movePhotosToAlbumAjax/',
                data: {
                    "photo_id": photo_id,
                    "albumId": albumId,
                    _method: 'post'
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(response) {
                    console.log("de response terug");
                    console.log(response);
                    //$('#photo-' + url_id).remove();

                },
                error: function(qXHR, textStatus, errorThrown) {
                    console.log(JSON.stringify(jqXHR));
                    console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
                }
            });
        });
    });
});

This is the route.

    Route::post('users/photos/movePhotosToAlbumAjax/','[email protected]')->name('users.photos.movePhotosToAlbumAjax');

Got any ideas? Thanks in advance.

Edris899 left a reply on Sorry, The Page You Are Looking For Could Not Be Found Error

Haha is see the "/" and the missing id. Yeah that's one too haha

Edris899 left a reply on Sorry, The Page You Are Looking For Could Not Be Found Error

Holly maceroni haha. That was the fix mister! Thanks alot :D.

I am using jQuery alot lately and this is the effect of it haha :P

@Cronix thanks alot man.

Edris899 left a reply on Sorry, The Page You Are Looking For Could Not Be Found Error

I think the problem is in the html. But don't know for sure

Edris899 left a reply on Sorry, The Page You Are Looking For Could Not Be Found Error

Cleared the cache and also placed the route above all. Didn't help. But in my html I am not using a route at this moment. I want to update the album and photo with the selected photo and then move it.

So I thought I need just a action...

Edris899 left a reply on Sorry, The Page You Are Looking For Could Not Be Found Error

Yes I think I do. Its alot.

    
    // User Album Routing
    Route::get('users/albums/home', '[email protected]')->name('users.albums.home');
    Route::get('users/albums/show/{id}', '[email protected]')->name('users.albums.show');
    Route::get('users/albums/create', '[email protected]')->name('users.albums.create');
    Route::get('users/albums/addPhoto/{id}', '[email protected]_Photo')->name('users.albums.addPhoto');
    Route::post('users/albums/addPhotoStore/{id}', '[email protected]_Photo_Store')->name('users.albums.addPhotoStore');
    Route::get('users/albums/edit/{id}', '[email protected]')->name('users.albums.edit');
    Route::put('users/albums/edit/{id}', '[email protected]')->name('users.albums.update');
    Route::post('users/albums/store', '[email protected]')->name('users.albums.store');
    Route::delete('users/albums/destroy/{id}', '[email protected]')->name('users.albums.destroy');

    // User Photo Routing
    Route::get('users/photos/home', '[email protected]')->name('users.photos.home');
    Route::get('users/photos/show/{id}', '[email protected]')->name('users.photos.show');
    Route::get('users/photos/create', '[email protected]')->name('users.photos.create');
    Route::post('users/photos/store', '[email protected]')->name('users.photos.store');
    Route::post('users/photos/store', '[email protected]')->name('users.photos.storeRequest');
    Route::get('users/photos/edit/{id}', '[email protected]')->name('users.photos.edit');
    Route::put('users/photos/edit/{id}', '[email protected]')->name('users.photos.update');

    Route::post('users/albums/store/{id}', '[email protected]')->name('users.photos.storePhotosToAlbum');

    Route::get('users/photos/editNonProcessed/{id}', '[email protected]')->name('users.photos.editNonProcessed');
    Route::put('users/photos/edit/{id}', '[email protected]')->name('users.photos.storeRequestProcessed');

    Route::delete('users/photos/destroy/{id}', '[email protected]')->name('users.photos.destroy');

    Route::get('users/photos/viewNonProcessed/{id}', '[email protected]')->name('users.photos.viewNonProcessed');

    Route::put('users/photos/movePhotosToAlbum/{$id}','[email protected]')->name('users.photos.movePhotosToAlbum');

Edris899 left a reply on Sorry, The Page You Are Looking For Could Not Be Found Error

Does it mather if the form is in a modal popup from bootstrap?

Edris899 left a reply on Sorry, The Page You Are Looking For Could Not Be Found Error

@Snapey The $album->id isn't empty it's showing the right album id

Edris899 left a reply on Sorry, The Page You Are Looking For Could Not Be Found Error

the link is in the browser in chrome. That's what I get after submitting the form. Gonna check if $album->id is null

Edris899 left a reply on Sorry, The Page You Are Looking For Could Not Be Found Error

@bobbybouwmann Thanks for the reply.

I did what you said but I still get that error. It seems like it wants to open a page but that isn't the idea. It has to redirect and in the controller that code is there.

This is the code that I used.

<div class="col-lg-12">
   <form role="form" method="POST" action="{{action('[email protected]', $album->id)}}">
      @method('PUT')
      @csrf
      <div class="form-group">
         <label for="exampleFormControlSelect1">Choose a album</label>
         <select class="form-control" id="exampleFormControlSelect1">
            @foreach($albums as $album)
            <option value="{{$album->id}}">{{$album->name}}</option>
            @endforeach
         </select>
      </div>
      <div class="row">
         <div class="col-lg-6 offset-lg-3">
            <button type="submit" class="btn btn-success">Move Illustrations</button>
         </div>
      </div>
   </form>
   <br/>
</div>

This is the route in web.php

Route::put('users/photos/movePhotosToAlbum/{$id}','[email protected]')->name('users.photos.movePhotosToAlbum');

And this is the controller.

public function movePhotosToAlbum(Request $request,$id){
        dd("hi");
        
        $currentAlbum = Album::findOrFail($id);
        $newAlbum = $request->album->id;

        return redirect()->route('users.photos.home');

    }

It doesn't die in the function. The http link is like this.

http://www.test.nl.test/users/photos/movePhotosToAlbum/52

Edris899 started a new conversation Sorry, The Page You Are Looking For Could Not Be Found Error

Hi there,

I am building a illustration & album website with laravel 5. I am trying to move the selected illustration to another album. I do that with a button and a modal popup from bootstrap.

I just want to perform an action on the controller but it want a page or something?

This is the html code.

<div class="col-lg-12">
   <form role="form" method="put" action="{{action('[email protected]', $album->id)}}">
      @csrf
      <div class="form-group">
         <label for="exampleFormControlSelect1">Choose a album</label>
         <select class="form-control" id="exampleFormControlSelect1">
            @foreach($albums as $album)
            <option value="{{$album->id}}">{{$album->name}}</option>
            @endforeach
         </select>
      </div>
      <div class="row">
         <div class="col-lg-6 offset-lg-3">
            <button type="submit" class="btn btn-success">Move Illustrations</button>
         </div>
      </div>
   </form>
   <br/>
</div>

This is the function in the controller.

public function movePhotosToAlbum(Request $request,$id){
        dd("hi");
        
        $currentAlbum = Album::findOrFail($id);
        $newAlbum = $request->album->id;

        return redirect()->route('users.photos.home');

    }

The problem is that it doesn't get to the function. It doesn't perform that. Any ideas why?

Thanks in advance!

Edris899 left a reply on Data Of A Week.

Nice bro :D Good thing that you posted the solution. Better for the community. Good job.

Edris899 left a reply on How To Make A Query To Filter With A Pivot Table & Another Table In Laravel 5?

Hmmm I don't know but I made this with your help.

 public function processed()
    {
        return $this->photos->where('processed',0)->all();
    }

This works! Only I added that zero. I don't know if thats good/oke?

Edris899 left a reply on How To Make A Query To Filter With A Pivot Table & Another Table In Laravel 5?

@aurawindsurfing I get the following error

Method Illuminate\Database\Eloquent\Collection::whereNotNull does not exist.

Edris899 left a reply on How To Make A Query To Filter With A Pivot Table & Another Table In Laravel 5?

Hi @aurawindsurfing thanks alot for the reply. Gonna try it. I do. I do have a model.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\AlbumPhoto;
use App\Photo;
use App\Album;
use Role;

class Album extends Model
{
    protected $fillable = ['name','description','cover_image','user_id'];
    

    // public function albums(){
    //     return $this->hasMany('App\Album', 'album');
    // }
    public function album_photos(){
        return $this->hasMany('App\AlbumPhoto', 'album_id');
    }



    public function photos(){
        return $this->belongsToMany('App\Photo')->using('App\AlbumPhoto')->withTimestamps();
    }
}

Edris899 left a reply on Data Of A Week.

Hmmmm try this. The code is looking for the datetime at that moment and subtracts the subweek or 7 days of that datetime.

Then we use that to get data but here it's getting a little bit blurry for me haha,

$date = new Carbon\Carbon;
$date->subWeek();

$samplingData = DB::table('sampling_order')
            ->select('id','doctorselected','date','products','quantity')->where('created_at', '>', $date->toDateTimeString() )
            ->get();

  return view('layouts.Representativesampling')->with('data',['doctor_name' => $doctor_name, 'samplingData' => $samplingData ]);

Goodluck got to go. Google laravel 5 get only data from a week

Edris899 left a reply on Data Of A Week.

Hmmm not a pro but what do you think of this. Mayby it will help you

$date = new Carbon\Carbon; //  DateTime string will be 2014-04-03 13:57:34

$date->subWeek(); // or $date->subDays(7),  2014-03-27 13:58:25

News::where('created_at', '>', $date->toDateTimeString() )->get()

Edris899 left a reply on Data Of A Week.

You could use Carbon.

Check this site. https://scotch.io/tutorials/easier-datetime-in-laravel-and-php-with-carbon

Or do you mean a query?

Edris899 left a reply on A Simple MVC Example

You can also use php artisan to make a model.

Type the following in your terminal. You have to be in the same directory as your project. Same for windows

php artisan make:model Product

Edris899 started a new conversation How To Make A Query To Filter With A Pivot Table & Another Table In Laravel 5?

Hi there,

Sorry for the title I really don't know what to call it.

I am building a illustration website with albums. A illustration can be uploaded to a album.

In the photos table I have a processed table in it. This way I can check if the illustration was processed or not, if yes then it can be searchable if not then the user must edit the processed illustration or illustrations.

I can select the photos in the specific album but I don't know how to filter with the processed illustration belonging to the viewing album.

Also I have a seperate table album_photos table. The relation of a album and a photo is hasMany and belongsToMany.

This way I select all the photos but not filtered with processed or not.

        $photos = Photo::whereIn('id', $album -> album_photos() -> pluck('photo_id'))->get();

And this way I select all the processed photos of the corresponding user.

        $photosNotProcessed = Photo::where('user_id', Auth::user() -> id)->whereNull('processed')->get();

Now I want to select the photos in the viewing album that is not been processed. Any ideas?

Thanks in advance.

01 Sep
11 months ago

Edris899 left a reply on Laravel 5 Ajax Delete Request 405 Method Not Allowed Error

@Cronix It worked bro. You are the best ! :D :D:D It can be closed

Edris899 left a reply on Laravel 5 Ajax Delete Request 405 Method Not Allowed Error

@Cronix Thanks I tried that. I works now without the error it also deleted the album.

This is the code that I used.

$( "#delete" ).on( "click", function() {
                $("input:checkbox:checked").each(function () {
                    var $input = $( this );
                    console.log("Id: " + $input.attr("id") + " Value: " + $input.val());
                    
                    var url_id = $input.attr("id");
                    
                    $.ajax({
                        type: "post",
                        url: '/users/albums/destroy/' + url_id,
                        data: {"id": url_id , _method: 'delete'},
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        success: function (data) {
                            console.log("success yes");
                            
                            //$("#url" + url_id).remove();
                        },
                        error: function (data) {
                            console.log('Error:', data);
                        }
                    });
                });
            });

This is in the controller the destroy method.

public function destroy($id){
        $album = Album::findOrFail($id);
        $count_photos = $album->photos()->count();
        //Delete the image on the public storage 
        if(Storage::delete('public/album_covers/'.$album->cover_image)){
            if($count_photos == 0){
                $album->delete();
                return redirect()->route('users.albums.home')->with('success', 'Album Deleted!');
            }
            else{
                foreach ($album->photos as $photo) {
                    $photo_id = $photo->pivot->photo_id;
                    $album->photos()->detach($photo_id);
                }
                $album->delete();
                // return redirect()->route('users.photos.home')->with('success', 'Album Deleted!');
                return ['success' => true];
            }
        }
    }

But the problem now is that the page isn't refreshing so it still shows the deleted album only to know that after refresh its gone.

And that's because of no redirect or refreshing of the page to get the new/updated albums record.

Any suggestion? BTW thanks alot for responding to my problem.

Edris899 left a reply on Laravel 5 Ajax Delete Request 405 Method Not Allowed Error

Hi, I tried to change the request type to post in the ajax section as you said. But now it dumps all the html in the console of chrome.

Its posting the whole html body I think :(

Edris899 started a new conversation Laravel 5 Ajax Delete Request 405 Method Not Allowed Error

HI there,

#PC Specs:

- Ubuntu 18.04.1 LTS
- PHP 7.2.9
- Using apache2.

I am trying to remove a album or more with Laravel 5, jQuery & Ajax. That works ! The user can select one album with a checkmark or multiple albums to delete with a button.

The problem is, I get a this in the console of chrome.

DELETE http://www.test.nl.test/users/albums/home 405 (Method Not Allowed) Error: {readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}

This is my route:

 Route::delete('users/albums/destroy/{id}', '[email protected]')->name('users.albums.destroy');

This is the button

<div><button class='btn btn' style='background-color:#cfd8dc;' id="delete" type="submit" data-token="{{ csrf_token() }}"><i class="fas fa-trash grayText"></i></button></div>

This is the foreach loop for the album

<div class="row">
                @foreach($albums as $album)
                <div class="col-lg-2">
                    <div class="content">
                      <a id="overlay" >

                        <div class="content-overlay">
                            <div class="col-lg-2">
                                <label class="checkbox_custom">
                                    <input type="checkbox" name="checkbox_custom_a" id="{{$album->id}}">
                                    <span class="checkmark"></span>
                                </label>
                            </div>
                        </div>

                        <img href="{{route('users.albums.show',$album->id)}}" class="content-image" src="https://images.unsplash.com/photo-1433360405326-e50f909805b3?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=359e8e12304ffa04a38627a157fc3362">
                        <div class="content-details fadeIn-bottom">
                          <h3 class="content-title">{{$album->name}}</h3>
                          <p class="content-text">{{$album->description}}</p>
                        </div>
                      </a>
                    </div>
                    <br>
                </div>
              @endforeach
        </div>

This is the jQuery that I use.

$( "#delete" ).on( "click", function() {
                $("input:checkbox:checked").each(function () {
                    var $input = $( this );
                    console.log("Id: " + $input.attr("id") + " Value: " + $input.val());
                    
                    var url_id = $input.attr("id");
                    
                    $.ajax({
                        type: "delete",
                        url: '/users/albums/destroy/' + url_id,
                        data: {"id": url_id , _method: 'delete'},
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        success: function (data) {
                            console.log(data);
                            
                            //$("#url" + url_id).remove();
                        },
                        error: function (data) {
                            console.log('Error:', data);
                        }
                    });

                });
            });

This is the controller:

public function destroy($id){
        $album = Album::findOrFail($id);
        $count_photos = $album->photos()->count();
        //Delete the image on the public storage 
        if(Storage::delete('public/album_covers/'.$album->cover_image)){
            if($count_photos == 0){
                $album->delete();
                return redirect()->route('users.albums.home')->with('success', 'Album Deleted!');
            }
            else{
                foreach ($album->photos as $photo) {
                    $photo_id = $photo->pivot->photo_id;
                    $album->photos()->detach($photo_id);
                }
                $album->delete();
                return redirect()->route('users.photos.home')->with('success', 'Album Deleted!');
            }
        }
    }

--UPDATE--

Tried to change request type to post but I will dump the whole html body in the console. meh :(