2
votes

I have defined three routes in my Web.php tow of them work but one of them dose not work this below one Route::get('/tdownload/show','DownloadController@showdownload');. it dose not redirect to '/tdownload/show' URL from DownloadLogicController, in the mentioned controller i check if the entered URL is a valid URL for downloading and then want to redirect to show page with URL but it dose not work and just shows a white page
thanks in advance.

  Route::get('/tdownload','DownloadController@index');
  Route::post('/tdownload/download','DownloadController@store');
  Route::get('/tdownload/show','DownloadController@showdownload');

here are my views

enter image description here

@extends('download_dir.downloadlayout')

@section('content')

<div class="container">
                  <div class="notification rtl">
                    This container is <strong>centered</strong> on desktop.
                      <form action="/tdownload/download" method="post">
                      @csrf
                      @method('post')
                          <input type="search" name="search" id=""  class="search box" >

                        <!-- <select id="test" name>
                        <option value="1">American Black Bear</option>
                        <option value="2">Asiatic Black Bear</option>
                        <option value="3">Brown Bear</option>
                        <option value="4">Giant Panda</option>
                        <option value="5">Sloth Bear</option>
                        <option value="6">Sun Bear</option>
                        <option value="7">Polar Bear</option>
                        <option value="8">Spectacled Bear</option>
                      </select> -->


                        <button type="submit" class=" button is-medium  submit is-primary">download</button>

                      </form>

                </div>



@endsection

here are my controllers and the related codes

enter image description here

DownloadLogicController.php

<?php

namespace App\Http\Controllers;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request as re;
use Illuminate\Http\Request;
use App\Download;
use Response;
use Redirect;

use Illuminate\Support\Facades\Storage;
class DownloadLogicController extends Controller
{
    //




    function does_url_exists($url) {
   ini_set('default_socket_timeout', 520);
      $headers=@get_headers($url);
     return stripos($headers[0],"200 OK")?true:false;


   //  $client = new GuzzleHttp\Client();
//     $client = new Client([
//       // Base URI is used with relative requests
//       'base_uri' => $url,
//       // You can set any number of default request options.
//       'timeout'  => 2.0,
//   ]); 


    //   $client = new Client();
      // $request = $client->head($url);

            // try {
            //   
            //    return true;
            // } catch (Guzzle\Http\Exception\CurlException $e) {
            //    return false;
            // }        

        //     try {
        //        $client->head($url);
        //    } catch (\GuzzleHttp\Exception\ConnectException $e) {
        //        // log the error here

        //        // Log::Warning('guzzle_connect_exception', [
        //        //         'url' => $this->request->fullUrl(),
        //        //         'message' => $e->getMessage()
        //        // ]);
        //        return false;
        //    } catch (\GuzzleHttp\Exception\RequestException $e) {

        //        // Log::Warning('guzzle_connection_timeout', [
        //        //         'url' => $this->request->fullUrl(),
        //        //         'message' => $e->getMessage()
        //        // ]);
        //        return false;
        //    }



  }

    public function doDownloading(Download $download){

         $download_link = request()->validate(['search'=>'required']);

        $s = $this->does_url_exists($download_link['search']);
         // /dd($s);

         if($s){

            //  dd($s)  ;
             $sended_url = $download_link['search'];
            //  dd($sended_url);
            return redirect('/tdownload/show')->with($sended_url);


         } else{
             // return redirect('/download');
             dd('noo');
         }

         /* 
            1 check wheather it is a validate download link and downloaddble.
            2 if it is so , save it in a variable and send it as parameter to
               show method 
            3 create a project on the database and save the project.

            4 redirects to show page

         */


         // $download::create([]);
         // dd($download_link);


    }
}

DownloadController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Download;
use App\Http\Controllers\DownloadLogicController;

class DownloadController extends Controller
{
    //

            public function index(){

                return view('download_dir.downloadmainpage');
            }

            public function showdownload(){


                return view('download_dir.showingdownload');

            }


            public function store(DownloadLogicController $doDownload ){

                $d = new Download();
                //  $doDownload = new DownloadLogicController;
                $doDownload->doDownloading($d);


                // return redirect('/tdownload/show');
            }
}
3

3 Answers

0
votes

try this one

  Route::get('/tdownload','DownloadController@index');
  Route::post('/tdownload/download','DownloadController@store');
  Route::get('/different/tdownload/show','DownloadController@showdownload');

or

  Route::get('/tdownload/show','DownloadController@showdownload');
  Route::get('/tdownload','DownloadController@index');
  Route::post('/tdownload/download','DownloadController@store');

sometimes its work for me hehehee

0
votes

try to give the route a name and call it in the blade

in the web : Route::get('/tdownload/show','DownloadController@showdownload')->name('download');

in the blade : route('download')

and make sure there is no other route have the same pattern or the same name

0
votes

Try this:

    Route::prefix('tdownload')->group(function () {
             Route::get('/','DownloadController@index')->name('download.index');
             Route::post('/download','DownloadController@store')>name('download.store');
             Route::get('/show','DownloadController@showdownload')>name('download.show');
});

Sometimes some route overrides another if they have same URL pattern. Grouping routes has helped me in similar scenario many times. Hope this helps you.

In view:

<a href="{{route('download.index')}}">Download</a>