Seeker1337

Seeker1337

Member Since 5 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
2 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
2 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
2 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
2 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
2 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
3 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
3 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
3 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
3 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
3 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
3 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
3 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
3 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>  


Dec
25
5 months ago
Activity icon

Replied to Laravel 6+ Force Redirections From Http To Https

Worked like a charm, thanks.

Dec
24
5 months ago
Activity icon

Replied to Laravel 6+ Force Redirections From Http To Https

What do you mean by all links?

Activity icon

Started a new Conversation Laravel 6+ Force Redirections From Http To Https

Hey there, I've recently uploaded my website to a VPS ( ubuntu 18.04 with webmin/virtualmin/lamp ) and added a Comodo SSL. However, when I try to access my website through http:// connection I get redirected to a blank page that's currently displaying the following text " Index of / " and below it " Name, Last modified, Size, Description". It's all blank it doesn't show any data.

The bad part is when I type my website's name in the tab and hit enter I get redirected to this http connection. My website's HTTPS connections are all set and running properly.

EDIT: It's also weird that when I get redirected to that blank page and hit Enter in the URL tab section I get redirected through the HTTPS connection. Its like if I type it twice I then get a proper connection. Here is my .htaccess file:


<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

        RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteEngine On 
    RewriteCond %{HTTP_HOST} ^my-domain\.com [NC]
    RewriteCond %{SERVER_PORT} 443 
    RewriteRule ^(.*)$ https://my-domain.com/ [R=301,L]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Here is my .env file:


APP_NAME=not important
APP_ENV=production
APP_KEY=not important
APP_DEBUG=false
APP_URL=https://my-domain.com

LOG_CHANNEL=daily


Dec
22
5 months ago
Activity icon

Replied to Laravel 6+ VPS Images Failing To Load And Showing Error 404

Manged to get it working, thank you mate.

Dec
21
5 months ago
Activity icon

Started a new Conversation Laravel 6+ VPS Images Failing To Load And Showing Error 404

Hello. I've recently uploaded my website to a VPS ( ubuntu 18.04 with Webmin/Virtualmin/LAMP ) and everything is working properly except the images. I didn't change any route or anything related to them and they work just fine on my localhost.

EDIT: Since the path is correct and I've linked the storage folder I'm sure it's a permissions' problem. I tried with -- sudo chmod 775 -R storage -- but it still won't work..

All my images are stored in storage/images folder. Let me show you my code on retrieving them and the error afterwards:


<img src="../storage/images/header/header-1.jpg" class="images">

And the error being:


Failed to load resource header-1.jpg : the server responded with a status of 404 (Not Found)


Here is also my current .htaccess configuration:

.htaccess


<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Activity icon

Awarded Best Reply on [SOLVED]Laravel 6+ VPS Pointing At The Wrong Directory

I managed to solve it.

Activity icon

Replied to [SOLVED]Laravel 6+ VPS Pointing At The Wrong Directory

Here is how my web.php starts:


Route::get('/', function () {
    return view('welcome');
});

EDIT: I think the problem is that it's reading it as a plain text.

Activity icon

Replied to [SOLVED]Laravel 6+ VPS Pointing At The Wrong Directory

I've actually managed to get rid of this. Now my project is laying inside /var/www. I created a new virtual host file instead of the default 000-default.conf one ( disabled this one ).

my-project.com.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName my-project.com
    ServerAlias www.my-project.com
    DocumentRoot /var/www/my-project.com/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Now when I type the domain name I get redirected to the public/index.php

public/index.php


<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <[email protected]>
 */

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__.'/../../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

Now the last step is to manage to redirect this to my home.blade.php first page instead of rendering this index.php file. I think this has to do with .htaccess. Any ideas? I'm currently browsing around the forums to find out a solution.

Activity icon

Started a new Conversation [SOLVED]Laravel 6+ VPS Pointing At The Wrong Directory

Hello. I've recently uploaded my website to a VPS ( Ubuntu 18.04 with Webmin/Virtualmin/LAMP ) but I ran into a few issues:

  1. Everything is set up as it should be but I'm having an issue with the files hierarchy. Here is how it looks at the moment:

/var/www/html/my-project/public

So, the problem is there is a "index.html" inside /var/www/html that gets rendered first and since it is outside of my project's folder it won't recognize any files inside my project when trying to @include them.

I edited my /etc/apache2/sites-available/000-default.conf and the DocumentRoot value to point to my Laravel public directory (/var/www/html/my-project/public) but still this file outside of the project gets pointed at and renders first.

Basically I need to point the VPS to my project's root folder and render home.blade.php first. Any help is appreciated.

Dec
20
5 months ago
Activity icon

Replied to Laravel 6+ VPS Hosting Files Structure Problems

Can anyone help me out?

Activity icon

Replied to Laravel 6+ VPS Hosting Files Structure Problems

Well, I guess so. It's my first time uploading a laravel app to a VPS. On my localhost the front page that renders is 'home.blade.php' and everything else is accessible with includes and so on.

Activity icon

Started a new Conversation Laravel 6+ VPS Hosting Files Structure Problems

Hello. I've recently uploaded my website to a VPS ( Ubuntu 18.04 with Webmin/Virtualmin/LAMP - Apache ) but I ran into a few issues:

  1. Everything is set up as it should be but I'm having an issue with the files hierarchy. Here is how it looks at the moment:

/var/www/html/my-project/public

Inside --- /var/www/html --- there is a index.php file that gets rendered first and here is the code inside that index.php

<!DOCTYPE html>
<html lang="en">
 <head>
     
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title></title>
    <meta name="description" content="">
  
</head>

<?php

include('layouts.header') 
include('layouts.middle')
include('layouts.middle2')
include('layouts.footer')    
    
?>

</html>  

Here I guess the problem is that this index.php is outside of 'my-project' and the 'PUBLIC' folder itself and it doesn't recognize my layouts' files. I've tried including the resources/views before the layouts but it still won't recognized. Basically, it's working because if I type a random text it gets displayed but I'm failing at the files hierarchy level. Any help is appreciated.

Dec
19
5 months ago
Activity icon

Replied to Laravel 6+ VPS Hosting Error 403 Access Forbidden

Yes, I did but now I'm getting other issues.. When I type the following command I get the following error:

sudo chown -R www-data:www-data /var/www/html/my-project
(Also tried with /public behind it )
sudo chown -R www-data:www-data /var/www/html/my-project/public

chown: cannot access '/var/www/html/my-project': No such file or directory
chown: cannot access '/var/www/html/my-project/public': No such file or directory

I don't know what Im doing wrong..

EDIT: Is my .htaccess file properly configd like that?

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Activity icon

Replied to Laravel 6+ VPS Hosting Error 403 Access Forbidden

Oh you almost saved my day. Thank you very much for the help but there is something else that has to be done: Now my website is displaying an 'Apache2 ubuntu Default page ' - If you can read this page, it means that the Apache HTTP server installed at this site is working properly. You should replace this file (located at /var/www/html/index.html) before continuing to operate your HTTP server.

With which file should I replace this one?

Also do I have to edit the ports or ServerAdmin in the 000-default.conf ? It looks like this now:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin [email protected]
    DocumentRoot /var/www/html/myapp/public

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


Activity icon

Replied to Laravel 6+ VPS Hosting Error 403 Access Forbidden

I don't know how to upload images here. The error is: You don't have permission to access this resource. There is a miss configuration somewhere but I don't know where. When I move the files out of 'PUBLIC' folder directly into 'public_html' I get error 500. When I keep the 'PUBLIC' folder itself in 'public_html' I get error 403..

Should I include /public in my APP_URL in .env. Also should my URL start with http or https ( I have SSL ).

Activity icon

Replied to Laravel 6+ VPS Hosting Error 403 Access Forbidden

I've done everything as it should be but I still get this 403 error. My root folder is outside of 'public_html' and only the 'PUBLIC' is inside it. The VPS is using PhP version 7.2.24

Activity icon

Replied to Laravel 6+ VPS Hosting Error 403 Access Forbidden

I've edited the .htaccess and .index.php files but now I'm getting a 403 error - access forbidden. I think this has to do something with pointing the domain to the /public?

Activity icon

Started a new Conversation Laravel 6+ VPS Hosting Error 403 Access Forbidden

Hello there. I've recently uploaded my website to a Virtual Private Server. The OS I'm currently using is - Ubuntu 18.04 with Webmin/Virtualmin/LAMP.

My domain points to the VPS ( although I haven't included /public nowhere in the pointing or in the domain. Do I have to? This /public folder is really giving me a hard time.. )

So, I've uploaded my project in the root directory and the 'PUBLIC' folder to 'public_html' directory.

So, when I try to access my website now I get - Error 403 - Access forbidden

Here is what I've changed in my files before uploading to the VPS:

.env

APP_NAME=random
APP_ENV=production
APP_KEY= I haven't touched this. I'm using the same key as on my localhost.
APP_DEBUG=false
APP_URL=https://www.mydomain.com

LOG_CHANNEL=daily

config/app.php


'name' => env('APP_NAME', 'random'),
'env' => env('APP_ENV', 'production'),
'debug' => env('APP_DEBUG', false),
'url' => env('APP_URL', 'https://www.mydomain.com'),
'asset_url' => env('ASSET_URL', null),

public_html -> ( Here I put all my folders/files from 'PUBLIC' without the folder itself ) ->index.php


require __DIR__.'/../app/vendor/autoload.php';
$app = require_once __DIR__.'/../app/bootstrap/app.php';


EDIT: I haven't changed anything in .htaccess .

Dec
14
5 months ago
Activity icon

Replied to Laravel 6+ Contact Form Send Email Error #535

I will check it out, thanks. I think the problem is in miss-matched configurations between my server and the .env file

Activity icon

Started a new Conversation Laravel 6+ Contact Form Send Email Error #535

Hey there. I have a Contact form in my website containing Email, Subject and content fields. However, when I click on 'Send message' I get the following error:

Failed to authenticate on SMTP server with username "myusername" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted.

EDIT: I have a Google Authenticator enabled for that email address.

Here are my files:

web.php

use Illuminate\Http\Request;
use App\Mail\ContactsMail;
use Illuminate\Support\Facades\Mail;

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

Route::post('/contacts', function(Request $request) {
    
    Mail::send(new ContactsMail($request)) ;
    return redirect('/') ;
    
}) ;

ContactsMail.php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Http\Request;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class ContactsMail extends Mailable
{
    use Queueable, SerializesModels;

    public $email ;
    
    public function __construct(Request $request) {
        
        $this->email = $request ;
    }

    
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build() {
        
        return $this->subject('New Contact Mail') 
                    ->from('[email protected]') 
                    ->to('[email protected]') 
                    ->view('emails.contacts-message') ;
        // Im not generating what's put through the contact form just because I wanted to test this out. Can this be the problem?
   }
       
}


emails folder -> contacts-message.blade.php

{{ $email->content }}

contacts.blade.php

<form action="{{ url('/contacts') }}" method="post">
@CSRF

<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-control">
</div>

<div class="form-group">
<label>Subject</label>
<input type="subject" name="subject" class="form-control">
</div>

<div class="form-group">
<label>Message</label>
<textarea  name="content" class="form-control"></textarea>
</div>

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

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl