5 months ago

Laravel 6+ Retrieve info from MySQL DB and send them to an archive page problems

Posted 5 months ago by Seeker1337

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.


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;


  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() ;


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

 <div class="form-group">
    <label for="gv-text3"> Phone number: </label>
    <input type="number" class="form-control" name="conphonenumber" required>
  <div class="form-group">
    <label for="gv-text4"> Information: </label>
    <textarea rows="6" cols="64" name="coninfo" required></textarea>
  <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">
    <th> №: </th>
    <th> Name: </th>
    <th> E-mail: </th>
    <th> Phone number: </th>
    <th> Information: </th>
    <th> Actions </th>
    foreach ($contactsmodel as $ContactsModel) {
    <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>
<?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') ;

Please sign in or create an account to participate in this conversation.