Seeker1337

Seeker1337

Member Since 6 Months Ago

Experience Points
1,310
Total
Experience

3,690 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
1,310 XP
Mar
15
3 months ago
Activity icon

Started a new Conversation Making A Css Table Vertical On Phone Devices

Hello there. I have a table that has up to 8 fields. I tried playing around with the media queries but I can't set it up properly. On desktop resolutions the table is horizontal and everything is streching nicely, however on phone devices it gets messy.

Basically on phone devices the table must become vertical, so the 'th' and 'td' are in an inline-block next to each other, else it's stretching really widely and it's almost unreadable.

Thank you all for the help. Here is what I have and what I have tried.

The table for desktop devices - horizontal


#customers {

font-family: "Trebuchet MS", Arial, Helvetica, sans-serif ;
border-collapse: collapse ;
width: 100% ;

}

#customers td, #customers th {

border: 1px solid #ddd ;
padding: 2px 2px ;
text-align: center ;

}

#customers tr:nth-child(even) {

background-color: #f2f2f2 ;

}

#customers tr:hover {

background-color: #ddd ;

}

#customers th {

width:8% ;    
padding-top: 12px ;
padding-bottom: 12px ;
background-color: #4CAF50 ;
color: white ;

}

The media query for phone devices I have tried - It must become vertical


@media (min-width: 320px) and (max-width: 480px) {

#customers {

max-width: 100% ;

}

#customers td, #customers th {

display: inline-block ;

}


}

Mar
11
3 months ago
Activity icon

Replied to Laravel 6 Improving My Forms' Security

Alright, thank you very much mate. I tried penetrating the search form using cross-site scripting but nothing went through. And since Im not escaping any characters I was a little bit concerned.

Activity icon

Replied to Laravel 6 Improving My Forms' Security

Oh I see, haven't spotted this one. Apart from that does everything else look secured? I'm mostly concerned about the search bar. Shall I escape characters there or something?

Activity icon

Started a new Conversation Laravel 6 Improving My Forms' Security

Hey there. Basically my website will be going live in the next few days and I wanted to make sure the forms are properly secured against SQL injection and XSS. I have 3 forms - Contact form/ Buying vehicles form and a Search form. I'm passing the CSRF token in all of them and validating in the controllers.

I'm more concerned about the search form, though. Also when I type something in the search bar, the current CSRF token gets showed in the url because of the GET method.

localhost/mywebsite/public/vehicles?_token=fQDtPw0WbbYOxSIfhSoLdld5DZePKGR9vkjaClFG&vehsearch=bmw&submit=

ContactsController.php


use App\ContactsModel ;

public function store(Request $request)
    {
          $contactsmodel = $request->validate([
            
            'contactsusername' => 'required|max:40' ,
            'contactsemail' => 'required|email|max:50' ,
            'contactsinfo' => 'required|max:700' ,
            
        ]) ;
        
        $contactsmodel = new ContactsModel ;
        
        $contactsmodel->contactsusername = $request->contactsusername ;
        $contactsmodel->contactsemail = $request->contactsemail ;
        $contactsmodel->contactsinfo = $request->contactsinfo ;
        
        $contactsmodel->save() ;
        
        return redirect('contacts')->with('success', 'etc...') ;
    }


contacts.blade.php


<form action="{{ route('contacts.store') }}" method="POST" class="gv-po-form"> <br>
@CSRF
    
  <div class="form-group">
    <label for="gv-text">Name:</label>
    <input type="text" class="form-control" name="contactsusername"  required>
  </div>
    
 <div class="form-group">
    <label for="gv-text2"> E-mail: </label>
    <input type="email" class="form-control" name="contactsemail" required>
  </div>    
    
  <div class="form-group">
    <label for="gv-text3"> Information: </label>
    <textarea rows="6" cols="64" name="contactsinfo" required></textarea>
  </div>
  
  <button type="submit" class="btn btn-primary"> SEND </button> <br><br>
    
</form> 

VehiclesController.php

use App\VehiclesModel ;

public function store(Request $request)
    {
         $vehiclesmodel = $request->validate([
            
            'vehusername' => 'required|max:40' ,
            'vehphonenumber' => 'required|max:40' ,
            'vehemail' => 'required|email|max:40' ,
            'vehinfo' => 'required|max:700' ,
            'vehimages' => 'required' , 
            'vehimages.*' =>'image|mimes:jpeg,jpg,png',
          
        ]) ;
        
        
        $destinationPath = 'storage/veh-images' ;
        $vehimages = array() ;
        
        if($files=$request->file('vehimages')) {
            
        foreach($files as $file) {
            
            $filename = $file->getClientOriginalName() ;
            $file->move($destinationPath, $filename) ;
            $vehimages[] = $filename;
          }
        }
        //implode images with pipe symbol
        $vehallimages = implode("|",$vehimages) ;
        
        $vehiclesmodel = new VehiclesModel ;
        
        $vehiclesmodel->vehusername = $request->vehusername ;
        $vehiclesmodel->vehphonenumber = $request->vehphonenumber ;
        $vehiclesmodel->vehemail = $request->vehemail ;
        $vehiclesmodel->vehinfo = $request->vehinfo ;
        $vehiclesmodel->vehimages = $vehallimages ;
        
        $vehiclesmodel->save() ;
        
        return redirect('vehicles')->with('success', 'etc..') ;
        
    }


vehicles.blade.php


<form action="{{ route('vehicles.store') }}" method="POST" enctype="multipart/form-data" class="gv-po-form"> <br>
@CSRF    
    
  <div class="form-group">
    <label for="gv-text">Name:</label>
    <input type="text" class="form-control" name="vehusername" required>
  </div>
    
  <div class="form-group">
    <label for="gv-text2">Phone number:</label>
    <input type="number" class="form-control" name="vehphonenumber" required>
  </div>  
    
  <div class="form-group">
    <label for="gv-text3">E-mail:</label>
    <input type="email" class="form-control" name="vehemail" required>
  </div>     
    
  <div class="form-group">
    <label for="gv-text4"> Information: </label>
    <textarea rows="6" cols="64" name="vehinfo" required></textarea>
  </div>
    
  <div class="form-group">
    <label for="gv-text5"> Pictures of the vehicle: </label> <br>
    <input type="file" name="vehimages[]" multiple required>
  </div>    
  
  <button type="submit" name="submit" class="btn btn-primary"> SEND </button> <br><br>
    
</form>

VehSearchModel.php


    public function scopeSearch($vehsearchquery, $vehsearch)
    {
        $vehsearch = preg_replace('/\s+/', '%', $vehsearch) ;
        $vehsearch = "%{$vehsearch}%" ;

        $vehsearchquery->where(function ($vehsearchquery) use ($vehsearch) {
            $vehsearchquery->orWhere('vehmodel', 'like', $vehsearch);
            $vehsearchquery->orWhere('vehmark', 'like', $vehsearch);
            $vehsearchquery->orWhereRaw("CONCAT(vehmodel, ' ', vehmark) LIKE ?", [$vehsearch]);
    }) ;

    return $vehsearchquery ;
}

VehSearchController.php


  public function index(Request $request)
    {   
        $vehsearch = $request->input('vehsearch') ;
        
        $vehiclesmodel = VehiclesModel::latest()->search($vehsearch)->paginate(30) ;
        
        return view('vehicles', compact('vehiclesmodel', 'vehsearch')) ;
    }

vehicles.blade.php


 <form action="{{ route('vehicles.index') }}" method="GET" class="form-inline my-2 my-lg-0">
     <input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />    
     <input type="text" name="vehsearch" value="{{ isset($vehsearch) ? $vehsearch: '' }}"  class="form-control mr-sm-2" placeholder="search..." aria-label="Search">
     <button class="btn btn-outline-success my-2 my-sm-0" type="submit" name="submit"> Search </button>
 </form> 

Mar
06
3 months ago
Activity icon

Replied to Laravel 6 Eloquent Scope Search On Multiple Fields In One -Where- Clause

That's perfect mate. The concat is the perfect function here. Keep up the good work.

Mar
05
4 months ago
Activity icon

Replied to Laravel 6 Eloquent Scope Search On Multiple Fields In One -Where- Clause

Thank you for the good answer. It's almost working as supposed to be. Here is how it is now: Let's say I have 3 records - BMW 318, BMW 320, BMW 325.

Now when I type BMW 318, all the records containing "BMW" get pulled out. Even if I type e.g BMW 999 which mark doesn't exist, all the records containing "BMW" still get pulled out.

Activity icon

Started a new Conversation Laravel 6 Eloquent Scope Search On Multiple Fields In One -Where- Clause

Hello there. Basically I have a search functionality in my website that's working properly but I need to enchance it a little bit.

In short - If I search a vehicle by it's model ( e.g: BMW ) or by it's mark ( e.g: 320 ) it's working. However, I need to modify it to be able to search for both fields in one query ( e.g: BMW 320 ). I tried playing around with the where clause but I can't find the proper syntax.

VehiclesModel.php

class VehiclesModel extends Model
{
    
    protected $table = 'vehicles' ;
    protected $fillable = [
        
      'vehmod', 'vehmark', 'vehyear', 'vehengine', 'vehtrans', 'vehimage', 'vehgalimages' 
        
    ] ;
    
    public function scopeSearch($query, $vehsearch) {
               
        return $query->where('vehmod', 'like', '%' .$vehsearch. '%')
                     ->orWhere('vehmark', 'like', '%' .$vehsearch. '%') 

                     ->orWhere('vehmod', 'like', '%' .$vehsearch. '%' && 'vehmark', 'like', '%' .$vehsearch. '%')  ; // need to modify here
    }

   
}

VehiclesController.php

use App\VehiclesModel ;

class VehiclesController extends Controller
{
    public function index(Request $request)
    {   
        $vehsearch = $request->input('vehsearch') ;
        
        $vehiclesmodel = VehiclesModel::latest()->search($vehsearch)->paginate(30) ;
        
        return view('mypage', compact('vehiclesmodel', 'vehsearch')) ;
    }
}

Mar
04
4 months ago
Activity icon

Replied to Laravel 6 AJAX Live Search On CRUD Management Table

Managed to get it working by playing around with tags. Thank you.

Activity icon

Replied to Laravel 6 AJAX Live Search On CRUD Management Table

This should be defined in the 'action' function in the Controller. I've tried adding this inside td tags but I get redirected to an empty link. The EDIT method itself can't be triggered.

EDIT: Actually it's not reading this $row->id, its taking it as a plain text in the URL.

Activity icon

Started a new Conversation Laravel 6 AJAX Live Search On CRUD Management Table

Hello there. After a day of trying I hit a wall..basically I have the following problem:

I have a CRUD table that's holding records of vehicles that get retrieved from the MySQL database. I've been following a few tutorials and managed to set up AJAX live results search.

Now the problem comes from the fact that the logic is stored in a Controller. I can succesfully retrieve the details from the database using '-- foreach($data as $row) --' but I don't know how to retrieve the CRUD actions ( In this case Edit and Delete. The create method is separated from the table itself. I also can't succesfully retrieve the images)

I've tried putting the actions inside the td'. .'td. tags but I get Routing errors.

I also have a pagination which I don't know if it can work out with this AJAX live search? Any help is appreciated.

I have the code for the CRUD actions, images etc..inside "index.blade.php". They should be somehow implemented in the controller though.

VehiclesModel.php

class VehiclesModel extends Model
{
    
    protected $table = 'vehicles' ;
    protected $fillable = [
        
      'vehmod', 'vehmark', 'vehyear', 'vehengine', 'vehtrans', 'vehimage', 'vehgalimages' 
        
    ] ;

    
}

VehiclesController.php

use App\VehiclesModel ;
use DB ;


 public function store(Request $request)
    {
        
        $destinationPath = 'storage/veh-images' ;
        $vehgalimages = array() ;
        
        if($files=$request->file('vehgalimages')) {
            
        foreach($files as $file) {
            
            $filename = $file->getClientOriginalName() ;
            $file->move($destinationPath, $filename) ;
            $vehgalimages[] = $filename;
          }
        }
        //implode images with pipe symbol
        $vehallimages = implode("|",$vehgalimages) ;
        
        $vehiclesmodel = new VehiclesModel ;
        $vehiclesmodel->vehmod = $request->vehmod ;
        $vehiclesmodel->vehmark = $request->vehmark ;
        $vehiclesmodel->vehyear = $request->vehyear ;
        $vehiclesmodel->vehengine = $request->vehengine ;
        $vehiclesmodel->vehtrans = $request->vehtrans ;
        $vehiclesmodel->vehimage = $request->vehimage ;
        $vehiclesmodel->vehgalimages = $vehallimages ;
        
        $file = $vehiclesmodel->vehimage = $request->vehimage ;
        $filename = $file->getClientOriginalName() ;
        $destinationPath = 'storage/veh-images' ; 
        $vehiclesmodel->vehimage = $filename; 
        $uploadSuccess = $file->move($destinationPath, $filename);
        
        $vehiclesmodel->save() ;
        
        return redirect('management')->with('success', 'The record has been added succesfully!') ;
    }

function action(Request $request)
    {
     if($request->ajax())
     {
      $output = '' ;
      $query = $request->get('query') ;
      if($query != '')
      {

       $data = DB::table('vehicles')
         ->where('vehmod', 'like', '%'.$query.'%')
         ->orWhere('vehmark', 'like', '%'.$query.'%')
	 ->orWhere('vehyear', 'like', '%'.$query.'%')
	 ->orWhere('vehengine', 'like', '%'.$query.'%')
	 ->orWhere('vehtrans', 'like', '%'.$query.'%')
         ->orderBy('id', 'desc')
         ->get();
         
      }
      else
      {

       $data = DB::table('vehicles')
         ->orderBy('id', 'desc')
         ->get();
      }
      $total_row = $data->count();
      if($total_row > 0)
      {
       foreach($data as $row)
       {
        $output .= '
        
        <tr>
         <td>'.$row->vehmod.'</td>
         <td>'.$row->vehmark.'</td>
         <td>'.$row->vehyear.'</td>
         <td>'.$row->vehengine.'</td>
         <td>'.$row->vehtrans.'</td>
        </tr>
        // The CRUD actions should be implemented somehow here..
        ';
       }

      }
      else
      {
       $output = '
       <tr>
        <td align="center" colspan="5">No Data Found</td>
       </tr>
       ';
      }
      $data = array(
       'table_data'  => $output,
       'total_data'  => $total_row
      );

      echo json_encode($data);
     }
    }
    

index.blade.php (( Note: The CRUD actions and everything is here implemented succesfully. I however can't implement this in the controller ))

<?php use App\VehiclesModel ?>

<html lang="en">
 <head>
     
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
 
    <!-- Fonts -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" rel="stylesheet"  crossorigin="anonymous">
    <link href="{{ asset('css/styler.css') }}" rel="stylesheet">   
    <link rel="shortcut icon" type="image/x-icon" href=""> 
     
    <!-- JavaScript -->
    <script src="{{ asset('js/custom.js') }}"> </script>   
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
     
     
</head>    
    
<table id="customers">
       
<tr>
    <th> № </th>
    <th> Model </th>
    <th> Mark </th>
    <th> Year </th>
    <th> Engine </th>
    <th> Transmission </th>
    <th> Main pic </th>
    <th> Gallery images </th>
    <th> Actions </th>
</tr>
       
<?php   
  
    foreach ($vehiclesmodel as $VehiclesModel) {
    $vehallimages = explode("|", $VehiclesModel->vehgalimages) ;    
?>    
    
<tr>
    
    <td> {{ $VehiclesModel-->id }} </td>
    <td> {{ $VehiclesModel-->vehmod }} </td>
    <td> {{ $VehiclesModel-->vehmark }} </td>
    <td> {{ $VehiclesModel-->vehyear }} </td>
    <td> {{ $VehiclesModel-->vehengine }} </td>
    <td> {{ $VehiclesModel-->vehtrans }} </td>
    
    <td> 
        <img src="storage/veh-images/{{ $VehiclesModel->vehimage }}" class="ama-anc-avc-maingal-images">
    </td>
    
    <td>
        <?php
        foreach($vehallimages as $vehgalimages) {
        ?>
        <img src="storage/veh-images/{{ $vehgalimages }}" class="ama-anc-avc-maingal-images">
        <?php } ?>
    </td>
    
    <td> <a href="{{ route('index.edit', $VehiclesModel->id) }}"> <button type="button" class="btn btn-primary"> EDIT </button> </a> 
        
         <form action="{{ route('index.destroy', $VehiclesModel->id) }}" method="post">
             @CSRF
             @method('DELETE')    

             <button type="submit" class="btn btn-danger" style="width:65%; padding-top:2%;" name="submit"> DELETE </button>
         </form> 
    </td> 
    
</tr>
       
<?php  }  

echo $vehiclesmodel->links() ;

?>   
         
<a href="{{ route('index.create') }}"> <button type="button" class="btn btn-primary"> Add a record </button> </a> <br><br>
    
   
<div class="form-group">
<input type="text" name="search" id="search" class="form-control" placeholder="Search Customer Data" />
</div>

<h3 align="center">Total Data : <span id="total_records"></span></h3>

</table>

</html>     
    
<script>
$(document).ready(function(){

 fetch_customer_data();

 function fetch_customer_data(query = '')
 {
  $.ajax({
   url:"{{ route('management-ajax') }}",
   method:'GET',
   data:{query:query},
   dataType:'json',
   success:function(data)
   {
    $('#customers').html(data.table_data);
    $('#total_records').text(data.total_data);
   }
  })
 }

 $(document).on('keyup', '#search', function(){
  var query = $(this).val();
  fetch_customer_data(query);
 });
});
</script>


web.php

Route::get('index/action', '[email protected]')->name('management-ajax') ;

Route::resource('index', 'VehiclesController') ;  

Mar
02
4 months ago
Activity icon

Replied to Laravel 6 - I Would Need A Few Tips On Dynamic Pages

Can anyone give me some directions, please?

Activity icon

Replied to Laravel 6 - I Would Need A Few Tips On Dynamic Pages

But will they be dynamic pages or I'd have to create static ones? Basically what I need here is you click on the sidebar, choose a category ( e.g "engines" ) and you get redirected to a dynamic page retrieving all the results from the database that contain engines, in the autoparts.

Mar
01
4 months ago
Activity icon

Started a new Conversation Laravel 6 - I Would Need A Few Tips On Dynamic Pages

Hello there. Basically I have a page related to "Autoparts" and a sidebar containing around 30 different categories and sub-categories. When the user clicks on e.g "Engines" he/she should be redirected to a dynamic page containing only "Engines" ( as well as the sidebar again and the header ). ( www.mywebsite.com/autoparts/engines ). Or if the user clicks on "Brakes" he/she should be redirected to a dynamic page containing only "Brakes" ( as well as the sidebar again and the header ) .

I can do all of this with static pages but I don't think that's the best approach, since we are talking about many pages.

I don't have any code as of the moment but all I need from you guys is just a few tips on how to deal with this using "Dynamic pages". Shall I create a DB table storing URL paths or something like that? And then use routes that take the path and an unique ID?

I would be glad to code this myself but I'm not sure what's the best approach. Thank you all for your time and help.

Feb
28
4 months ago
Activity icon

Replied to Laravel 6+ Retrieve Info From MySQL DB And Send Them To An Archive Page Problems

Uh yea I got confused a little bit. It's working now, however when I click on the "Archive" button, I get sent to the new route with the $id but the column 'deleted_at' doesn't update. Basically nothing happens.

Activity icon

Started a new Conversation Laravel 6+ Retrieve Info From MySQL DB And Send Them To An Archive Page Problems

Hello there. In short, here's my structure and problem: I have a "Contact us" page with a simple form containing a few text fields. When the user submits the form a -STORE- method is triggered in the controller and the details get saved in the MySQL database. Then I retrieve the information in another page using @foreach and the ContactsModel. All good so far, no trouble.

What's next? After I've read the submitted form and dealt with it, I would like to be able to archive it in another page ( soft delete I guess ), so if anything happens I could just click on the "Archive" and be able to take a look at it again.

I've tried writing my own function in the ContactsController and call it upon clicking an 'Archive this' button but I kind of got stuck there.. Here's the error I get in the contacts-management.blade.php page: Missing required parameters for [Route: contacts.softdel] [URI: contacts-management/{$id}]. Any help is appreciated.

ContactsModel.php

use Illuminate\Database\Eloquent\SoftDeletes;
class ContactsModel extends Model
{
    use SoftDeletes;
    
    protected $table = 'contacts' ;
    protected $fillable = [
       
        'conusername', 'conemail', 'conphonenumber', 'coninfo'
        
    ] ;
    
    protected $date = ['deleted_at'] ;
    
    public $timestamps = false;
}

ContactsController.php

  public function store(Request $request)
    {
        $contactsmodel= new ContactsModel ;
        
        $contactsmodel->conusername = $request->conusername ;
        $contactsmodel->conemail = $request->conemail ;
        $contactsmodel->conphonenumber = $request->conphonenumber ;
        $contactsmodel->coninfo = $request->coninfo ;
        
        $contactsmodel->save() ;
        
         return redirect('contacts-page')->with('success', 'etc...') ;
    }

    public function softdel($id) {
        
        $contactsmodel = new ContactsModel ;
        
        ContactsModel::findOrFail($id)->delete() ;
        
    }

contacts-page.blade.php

<form action="{{ route('contacts.store') }}" method="POST" class="gv-po-form"> <br>
@CSRF
    
  <div class="form-group">
    <label for="gv-text">Name:</label>
    <input type="text" class="form-control" name="conusername"  required>
  </div>
    
 <div class="form-group">
    <label for="gv-text2"> E-mail: </label>
    <input type="email" class="form-control" name="conemail" required>
  </div>    

 <div class="form-group">
    <label for="gv-text3"> Phone number: </label>
    <input type="number" class="form-control" name="conphonenumber" required>
  </div>   
    
  <div class="form-group">
    <label for="gv-text4"> Information: </label>
    <textarea rows="6" cols="64" name="coninfo" required></textarea>
  </div>
  
  <button type="submit" class="btn btn-primary"> Submit</button> <br><br>
    
</form> <br><br>

contacts-management.blade.php ( The page where I retrieve the submitted contacts forms and browse through them. Here I want to click the button "Archive", so they can be sent to the contacts-archive.blade.php page )

<?php use App\ContactsModel ?>
    
<table id="cs">
       
<tr>
    <th> №: </th>
    <th> Name: </th>
    <th> E-mail: </th>
    <th> Phone number: </th>
    <th> Information: </th>
    <th> Actions </th>
</tr>
               
<?php   
  
    foreach ($contactsmodel as $ContactsModel) {
?>    
    
<tr> 
    <td> {{ $ContactsModel->id }} </td>
    <td> {{ $ContactsModel->conusername }} </td>
    <td> {{ $ContactsModel->conemail }} </td>
    <td> {{ $ContactsModel->conphonenumber }} </td>
    <td> {{ $ContactsModel->coninfo }} </td>
    <td> <a href="{{ route('contacts.softdel') }}">  <button type="button" class="btn btn-warning"> ARCHIVE </button> </a> </td>
</tr>
 
        
<?php    }     ?>   
         
</table>  

web.php

Route::get('contacts-page', function() {
    return view('contacts-page') ;
}) ;

Route::resource('contacts-management', 'ContactsController') ;

Route::get('contacts-management/{$id}', '[email protected]')->name('contacts.softdel') ;

Feb
27
4 months ago
Activity icon

Started a new Conversation Laravel 6+ CRUD Update All Text Fields Except Image Upload One

Hello there. In short, here is my problem: I have a CRUD system for students information. It's taking a few text fields and an image upload field. All good so far unless we go to the update method. If i update any field without touching the image upload one, I get the following error: " SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'studimage' cannot be null".

I've tried setting the "studimage" field to NULL by default but this way if I update any text field, the query runs through, however the current image basically gets set to NULL and there is nothing to display. Any help would be appreciated.

StudController.php

use App\StudModel ;

public function store(Request $request)
    {
        
        $studmodel = new StudModel ;
        $studmodel->studnum = $request->studnum ;
        $studmodel->studname = $request->studname ;
        $studmodel->studf = $request->studf ;
        $studmodel->studsp = $request->studsp ;
        $studmodel->studimage = $request->studimage ;
        
        $file = $studmodel->studimage = $request->studimage ;
        $filename = $file->getClientOriginalName() ;
        $destinationPath = 'storage/stud-images' ;
        $studmodel->studimage = $filename; 
        $uploadSuccess = $file->move($destinationPath, $filename);
        
        $studmodel->save() ;
        
        return redirect('mypage')->with('success', 'etc..') ;
    }

    public function edit($id)
    {
        
        $studmodel = StudModel::findOrFail($id) ;
        
        return view('mypage-edit', compact('studmodel')) ;
        
    }

    public function update(Request $request, $id)
    {
        
        $studmodel = StudModel::findOrFail($id) ;
        
        $studmodel->update([
            
        $studmodel->studnum = $request->studnum ;
        $studmodel->studname = $request->studname ;
        $studmodel->studf = $request->studf ;
        $studmodel->studsp = $request->studsp ;
        $studmodel->studimage = $request->studimage ;
            
        ]) ;
        
        return redirect('mypage')->with('success', 'etc..') ;
        
    }

mypage-edit.blade.php

use App\StudModel ;

<h1> Edit a record </h1><br>
  
<form action="{{ route('mypage.update', $studmodel->id) }}" method="post">
    @CSRF
    @method('PUT')
  
    <div class="form-group">
    <label for="text">Unique number:</label>
    <input type="number" class="form-control" name="studnum"  value={{ $studmodel->studnum }} >
    </div>

    <div class="form-group">
    <label for="text">Name:</label>
    <input type="text" class="form-control" name="studname"  value={{ $studmodel->studname }} >
    </div>

    <div class="form-group">
    <label for="text">Faculty:</label>
    <input type="text" class="form-control" name="studf" value={{ $studmodel->studf }} >
    </div>

    <div class="form-group">
    <label for="text">Stud spec:</label>
    <input type="text" class="form-control" name="studsp" value={{ $studmodel->studsp}}>
    </div>

    <div class="form-group">
    <label for="pic">Stud image:</label><br>
    <input type="file" name="studimage" id="ImageToUpload" value={{ $studmodel->studimage }}>
    </div>

    <button type="submit" class="btn btn-primary"> Edit the record </button>
  </form>   

Activity icon

Replied to Laravel 6+ Upload Multiple Images Through A Form

Its working now, great job mate. Thank you very much.

Activity icon

Replied to Laravel 6+ Upload Multiple Images Through A Form

I'm getting the error Undefined variable: vehimages in the file mypage.blade.php at this line: -- $allImages = explode("|",$vehimages); --

VehController.php -STORE- method

public function store(Request $request)
    {
        $destinationPath = 'storage/veh-images' ;
        $vehimages = array() ;
        
        if($files=$request->file('vehimages')) {
            
        foreach($files as $file) {
            
            $filename = $file->getClientOriginalName() ;
            $file->move($destinationPath, $filename) ;
            $vehimages[] = $filename;
          }
        }
        //implode images with pipe symbol
        $allImages = implode("|",$vehimages) ;
        
        $vehichlesmodel = new VehiclesModel ;
        
        $vehichlesmodel->vehmod = $request->vehmod ;
        $vehichlesmodel->vehmark = $request->vehmark ;
        $vehichlesmodel->vehyear = $request->vehyear ;
        $vehichlesmodel->vehengine = $request->vehengine ;
        $vehichlesmodel->vehtrans = $vehtrans ;
        $vehichlesmodel->vehimages = $allImages ;
        
        $vehichlesmodel->save() ;
        
         return redirect('mypage')->with('success', 'etc..') ;

        }     

mypage.blade.php

<?php   

    foreach ($vehiclesmodel as $VehiclesModel) {
    $allImages = explode("|",$vehimages);

?>    
    
<tr> 

    <td> {{ $VehiclesModel->id }} </td>
    <td> {{ $VehiclesModel->vehmod }} </td>
    <td> {{ $VehiclesModel->vehmark }} </td>
    <td> {{ $VehiclesModel->vehyear }} </td>
    <td> {{ $VehiclesModel->vehengine }} </td>
    <td> {{ $VehiclesModel->vehtrans }} </td>
    <td> 
    @php
        @foreach($allImages as $vehimages)
                <img src="storage/veh-images/{{$vehimages}}" height="50px" width="30%">
        @endforeach
    @endphp
    </td>
 
</tr>
 
<?php  }    ?>

Activity icon

Replied to Laravel 6+ Upload Multiple Images Through A Form

And I can loop through them or? Never used it.

Feb
24
4 months ago
Activity icon

Replied to Laravel 6+ Upload Multiple Images Through A Form

Hey mate this is working so far, thank you. I'd just like to ask you one more thing:

How can I display all of the images together with other information in another page?

mypage.blade.php


<?php   

    foreach ($vehiclesmodel as $VehiclesModel) {
?>    
    
<tr> 

    <td> {{ $VehiclesModel->id }} </td>
    <td> {{ $VehiclesModel->vehmod }} </td>
    <td> {{ $VehiclesModel->vehmark }} </td>
    <td> {{ $VehiclesModel->vehyear }} </td>
    <td> {{ $VehiclesModel->vehengine }} </td>
    <td> {{ $VehiclesModel->vehtrans }} </td>

    <td> 
        <img src="storage/veh-images/{{ $VehiclesModel->vehimage }}" height="50px" width="30%">
    </td>
 
</tr>
 
<?php  }    ?>

Activity icon

Replied to Laravel 6+ Upload Multiple Images Through A Form

Basically I need a separate table with just one field e.g 'vehgalleryimages' and loop through it? Do I also have to make controllers and so on? I kind of got confused with this one. Can't i just loop through my "vehimage" field and have an undefined amount of images?

Feb
22
4 months ago
Activity icon

Started a new Conversation Laravel 6+ Upload Multiple Images Through A Form

Hello. Basically I have a form that stores some information and an image in a MySql database. However, I have to change this to taking up to multiple images. I've tried looping through them with @foreach but can't get it working. Some help would be appreciated. Here is my code:

VehiclesModel.php


class VehiclesModel extends Model
{
    protected $table = 'vehs' ;
    protected $fillable = [
        
      'vehmod', 'vehmark', 'vehyear', 'vehengine', 'vehtrans', 'vehimage' 
        
    ] ; 
}


VehiclesController.php

use App\VehiclesModel ;

   public function store(Request $request)
    {
        
        $vehiclesmodel = new VehiclesModel ;
        $vehiclesmodel->vehmod = $request->vehmod ;
        $vehiclesmodel->vehmark = $request->vehmark ;
        $vehiclesmodel->vehyear = $request->vehyear ;
        $vehiclesmodel->vehengine = $request->vehengine ;
        $vehiclesmodel->vehtrans = $request->vehtrans ;
        $vehiclesmodel->vehimage = $request->vehimage ;
        
        $file = $vehiclesmodel->vehimage = $request->vehimage ;
 // ---Somewhere here I have to declare vehimage as an array and loop through it ---

        $filename = $file->getClientOriginalName() ;
        $destinationPath = 'storage/veh-images' ; 
        $vehiclesmodel->vehimage = $filename; 
        $uploadSuccess = $file->move($destinationPath, $filename);
        
        $vehiclesmodel->save() ;

        return redirect('mypage')->with('success', 'The record has been added succesfully!') ;
    }

VehiclesForm.blade.php


<form action="{{ route('mypage.store') }}" method="post" enctype="multipart/form-data">
      @CSRF
        <div class="form-group">
        <label for="text">Model:</label>
        <input type="text" class="form-control" name="vehmod" placeholder="Insert the model of the vehicle">
        </div>
      
        <div class="form-group">
        <label for="text">Mark:</label>
        <input type="text" class="form-control" name="vehmark" placeholder="Insert the mark of the vehicle">
        </div>
      
        <div class="form-group">
        <label for="number">Year:</label>
        <input type="number" class="form-control" name="vehyear" placeholder="Insert the year of the vehicle">
        </div>
      
        <div class="form-group">
        <label for="text">Engine:</label>
        <input type="text" class="form-control" name="vehengine" placeholder="Insert the engine of the vehicle">
        </div>

        <div class="form-group">
        <label for="text">Transmission:</label>
        <input type="text" class="form-control" name="vehtrans" placeholder="Insert the transmission of the vehicle">
        </div>

        <div class="form-group">
        <label for="pic">Vehicles pictures:</label> <br>
        <input type="file" name="vehimage[]" multiple>
        </div>

        <button type="submit" class="btn btn-primary">Add record</button>
  </form>

Feb
21
4 months ago
Activity icon

Replied to Laravel 6+ - Two CRUD Controllers In One Route::resource

Yeah I will have to add a few additional pages. I thought I can make it simpler but I was guessing right that there would be a Routing conflict. Thank you for the head-ups.

Activity icon

Started a new Conversation Laravel 6+ - Two CRUD Controllers In One Route::resource

Hey there. I have the following problem:

In my website I have a management page where I'm using two ( Create, Read, Update, Delete ) systems with two controllers and two models in order to store "autoparts" and "selling vehicles" in MySQL database, and then retrieve them in two pages in the website. Basically I haven't encountered any problems upon using the first controller and the first model but after I added the second controller with the second model I came to a some sort of a Routing conflict ( I guess ).

My models started messing up and I'm getting an error that they are missing or not recognized. If the first Route is the AutopartsController I get an error that my AutopModel is missing or not recognized. Then if I switch their places and the first Route is the VehiclesController I get an error that my VehiclesModel is missing or not recognized.

Here are my files. I will add only one controller because they are basically the same just working with different data, and I don't want to spam too much this topic. If needed I will add it too.

web.php

Route::resource('management', 'AutopartsController') ;
Route::resource('management', 'VehiclesController') ;

AutopartsController.php

<?php

namespace App\Http\Controllers ;

use App\AutopModel ;
use Illuminate\Http\Request ;

class AutopartsController extends Controller
{
    
    public function display() {
        
        return view('autoparts') ;
        
    }
    
    public function index()
    {
        
        $autopmodel = AutopModel::paginate(20) ;
        
        return view('management', compact('autopmodel')) ;
        
    }
    
    public function create()
    {
        
        return view('crud.create') ;
        
    }

    public function store(Request $request)
    {
        
        $autopmodel = new AutopModel ;
        $autopmodel->ancmod = $request->ancmod ;
        $autopmodel->ancmark = $request->ancmark ;
        $autopmodel->ancyear = $request->ancyear ;
        $autopmodel->ancpos = $request->ancpos ;
        $autopmodel->ancimage = $request->ancimage ;
        
        $file = $autopmodel->ancimage = $request->ancimage ;
        $filename = $file->getClientOriginalName() ;
        $destinationPath = 'storage/images' ; 
        $ancmodel->ancimage = $filename; 
        $uploadSuccess = $file->move($destinationPath, $filename);
        
        $autopmodel->save() ;

        return redirect('management')->with('success', 'The record has been added succesfully!') ;
    }

    public function show($id)
    {
        $autopmodel = AutopModel::findOrFail($id) ;
        
        return view('crud.show', compact('autopmodel')) ;
    }

    public function edit($id)
    {
        
        $autopmodel = AutopModel::findOrFail($id) ;
        
        return view('crud.edit', compact('autopmodel')) ;
        
    }

    public function update(Request $request, $id)
    {
        
        $autopmodel = AutopModel::findOrFail($id) ;
        
        $autopmodel->update([
            
        $autopmodel = new AutopModel ,
        $autopmodel->ancmod = $request->ancmod ,
        $autopmodel->ancmark = $request->ancmark,;
        $autopmodel->ancyear = $request->ancyear ,
        $autopmodel->ancpos = $request->ancpos ,
        $autopmodel->ancimage = $request->ancimage 
            
        ]);
        
        return redirect('management')->with('success', 'The record has been edited succesfully!') ;
        
    }

    public function destroy($id)
    {
        
        $autopmodel = AutopModel::whereId($id)->delete() ;
        
        return redirect('management')->with('warning', 'The record has been deleted succesfully!') ;
        
    }

}

management.blade.php

<div class="main_content">
        <div class="header"">Management system</div>  
    
        <div class="info">
            
            @include('layouts.flash-message') 
            
            @include('crud.index')
            @include('crud.create')

        @include('crudVehicles.index')
            @include('crudVehicles.create')

      </div>
</div>

Feb
07
4 months ago
Activity icon

Replied to Laravel 6+ Pagination On Page And CRUD Problems

I forgot to echo the link function and that's why I wasnt getting any output. Thank you all for the help. Problem solved.

Activity icon

Replied to Laravel 6+ Pagination On Page And CRUD Problems

Oh right what a mistake, thank you mate. It's working now but I don't get the output of [Next], [Previous] and the pages numbers themselves. Does this come with the in-built paginate or I must add something else as well? I also added $vehmodel->links() but nothing happens.

Activity icon

Replied to Laravel 6+ Pagination On Page And CRUD Problems

I've already tried that but basically nothing happens. When I also try to add $VehModel->links() or renders() in my index.blade.php I get the following error "Call to undefined method App\VehModel::render()"

Activity icon

Started a new Conversation Laravel 6+ Pagination On Page And CRUD Problems

Hello there. Basically I have a project related to vehicles and the structure is like this:

I have a CRUD system in a Management page where I add vehicles using a form and they get displayed in another page in my website. However, I've came to an issue and I'd need your help:

  1. In my CRUD system I need to make a pagination for up to 15 vehicles per a page ( lets say I have 90 vehicles, so I would need 6 pages ).
  2. In the page where the vehicles get displayed in my website I need to have a pagination for up to 30 vehicles per a page.
  3. In my VehController.php when I try the following code " $vehmodel = VehModel::all() ->paginate(15) " I get the following error " Method Illuminate\Database\Eloquent\Collection::paginate does not exist. ". I'm assuming I'm not adding the paginate method at the right place.
  4. Can I make two different paginations using one controller? In my case 'VehController.php'

I've been reading about Laravel's pagination but got confused with using the paginate method on the query builder or an Eloquent query. Here is my code:

VehController.php

<?php

namespace App\Http\Controllers ;

use App\VehModel ;
use Illuminate\Http\Request ;

class VehController extends Controller
{
    
    public function display() {
        
        return view('vehicles')  ; // the page in my website where vehicles get displayed
        
    }
    
    public function index()
    {
        
        $vehmodel = VehModel::all() ; // tried adding pagination(15) here but I get an error
        
        return view('management', compact('vehmodel')) ; // management page
        
    }
    
    public function store(Request $request)
    {
        
        $vehmodel = new VehModel ;
        $vehmodel->vehmod = $request->vehmod ;
        $vehmodel->vehmark = $request->vehmark ;
        $vehmodel->vehyear = $request->vehyear ;
        $vehmodel->vehengine = $request->vehengine ;
        $vehmodel->vehtrans = $request->vehtrans ;
        $vehmodel->vehimage = $request->vehimage ;
        
        $file = $vehmodel->vehimage = $request->vehimage ;
        $filename = $file->getClientOriginalName() ;
        $destinationPath = 'storage/veh-images' ; 
        $vehmodel->vehimage = $filename; 
        $uploadSuccess = $file->move($destinationPath, $filename);
        
        $vehmodel->save() ;

        return redirect('management')->with('success', 'The record has been created succesfully!') ;
    }

    public function show($id)
    {
        $vehmodel = VehModel::findOrFail($id) ;
        
        return view('crud.show', compact('vehmodel')) ;
    }

    public function edit($id)
    {
        
        $vehmodel = VehModel::findOrFail($id) ;
        
        return view('crud.edit', compact('vehmodel')) ;
        
    }

    public function update(Request $request, $id)
    {
        
        $vehmodel = VehModel::findOrFail($id) ;
        
        $vehmodel->update($request->all()) ;
        
        return redirect('management')->with('success', 'The record has been redacted succesfully!') ;
        
    }

    public function destroy($id)
    {
        
        $vehmodel = VehModel::whereId($id)->delete() ;
        
        return redirect('management')->with('warning', 'The record has been deleted succesfully!') ;
        
    }
}


index.blade.php

<?php use App\VehModel ?>

<div id="crud-onclick-display2"> 
    <table id="customers">
    
<tr>
    <th> № </th>
    <th> Model </th>
    <th> Mark </th>
    <th> Year </th>
    <th> Engine </th>
    <th> Transmission </th>
    <th> Picture </th>
    <th> Actions </th>
</tr>
    
<?php   
    $vehmodel = VehModel::all() ;
    foreach ($vehmodel as $VehModel) {
?>    
    
<tr>
    
    <td> {{ $VehModel->id }} </td>
    <td> {{ $VehModel->vehmod }} </td>
    <td> {{ $VehModel->vehmark }} </td>
    <td> {{ $VehModel->vehyear }} </td>
    <td> {{ $VehModel->vehengine }} </td>
    <td> {{ $VehModel->vehtrans }} </td>
    <td> 
        <div class="image-container">
        <img src="storage/veh-images/{{ $VehModel->vehimage }}" height="50%" width="50%" alt="">
        </div> 
    </td> 
    <td> <a href="{{ route('management.show', $VehModel->id) }}"> <button type="button" class="btn btn-primary"> Edit </button> </a> 
         <form action="{{ route('management.destroy', $VehModel->id) }}" method="post">
             @CSRF
             @method('DELETE')    

             <input type="submit" name="submit" value="Delete" style="padding:6px 6px; width:63%; background-color:red; color:white">
         </form> 
    </td> 
    
</tr>
 
<?php  }  ?>   
    
    
</table>
</div>