1. Go to this page and download the library: Download xchimx/laravel-unsplash library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Xchimx\UnsplashApi\UnsplashService;
class UnsplashController extends Controller
{
protected $unsplashService;
public function __construct(UnsplashService $unsplashService)
{
$this->unsplashService = $unsplashService;
}
public function search()
{
$photos = $this->unsplashService->searchPhotos('Nature');
return view('unsplash.search', compact('photos'));
}
}
use Xchimx\UnsplashApi\Facades\Unsplash;
class UnsplashController extends Controller
{
public function search()
{
$photos = Unsplash::searchPhotos('Nature');
return view('unsplash.search', compact('photos'));
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Xchimx\UnsplashApi\Facades\Unsplash;
class UnsplashController extends Controller
{
public function search(Request $request)
{
$query = $request->input('query', 'Nature');
$photos = Unsplash::searchPhotos($query);
return view('unsplash.search', compact('photos', 'query'));
}
}
namespace App\Http\Controllers;
use Xchimx\UnsplashApi\Facades\Unsplash;
class UnsplashController extends Controller
{
public function show($id)
{
$photo = Unsplash::getPhoto($id);
return view('unsplash.show', compact('photo'));
}
}
namespace App\Http\Controllers;
use Xchimx\UnsplashApi\Facades\Unsplash;
class RandomPhotoController extends Controller
{
public function show()
{
$photo = Unsplash::getRandomPhoto();
return view('photos.random', compact('photo'));
}
}
namespace App\Http\Controllers;
use Xchimx\UnsplashApi\Facades\Unsplash;
class UnsplashController extends Controller
{
public function download($id)
{
$downloadUrl = Unsplash::getPhotoDownloadLink($id);
return redirect($downloadUrl);
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Xchimx\UnsplashApi\Facades\Unsplash;
class CollectionController extends Controller
{
public function index(Request $request)
{
$page = $request->input('page', 1);
$collections = Unsplash::listCollections(15, $page);
return view('collections.index', compact('collections'));
}
}
namespace App\Http\Controllers;
use Xchimx\UnsplashApi\Facades\Unsplash;
class CollectionController extends Controller
{
public function show($id)
{
$collection = Unsplash::getCollection($id);
return view('collections.show', compact('collection'));
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Xchimx\UnsplashApi\Facades\Unsplash;
class UserController extends Controller
{
public function user($username, Request $request)
{
$user = Unsplash::getUser($name);
return view('user', compact('user'));
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Xchimx\UnsplashApi\Facades\Unsplash;
class UserController extends Controller
{
public function photos($username, Request $request)
{
$page = $request->input('page', 1);
$photos = Unsplash::getUserPhotos($username, 15, $page);
return view('users.photos', compact('photos', 'username'));
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Xchimx\UnsplashApi\Facades\Unsplash;
class CollectionController extends Controller
{
public function search(Request $request)
{
$query = $request->input('query', 'Nature');
$page = $request->input('page', 1);
$collections = Unsplash::searchCollections($query, 15, $page);
return view('collections.search', compact('collections', 'query'));
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Xchimx\UnsplashApi\Facades\Unsplash;
class CollectionController extends Controller
{
public function searchWithTimeout(Request $request)
{
// Use withOptions to set custom Guzzle options, e.g., timeout
$photos = Unsplash::withOptions(['timeout' => 2])->searchPhotos('Nature');
return view('unsplash.search', compact('photos'));
}
}
Route::middleware(['unsplash.rate_limit'])->group(function () {
Route::get('/unsplash/search', [UnsplashController::class, 'search'])->name('unsplash.search');
// Other routes...
});
public function search(Request $request)
{
try {
$photos = Unsplash::searchPhotos('Nature');
} catch (\Exception $e) {
// Log the error or display a user-friendly message
return back()->withErrors('There was a problem communicating with the Unsplash API.');
}
return view('unsplash.search', compact('photos'));
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.