You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And modify the configuration file located at `app/config/packages/wtfz/tmdb/config.php` accordingly.
44
+
Next you can modify the generated configuration file `tmdb.php` accordingly.
39
45
40
46
That's all! Fire away!
41
47
42
-
Usage
43
-
----------------
48
+
## Usage
49
+
We can choose to either use the `Tmdb` Facade, or to use dependency injection.
50
+
51
+
### Facade example
52
+
The example below shows how you can use the `Tmdb` facade.
53
+
If you don't want to keep adding the `use Tmdb\Laravel\Facades\Tmdb;` statement in your files, then you can also add the facade as an alias in `config/app.php` file.
54
+
```php
55
+
use Tmdb\Laravel\Facades\Tmdb;
44
56
45
-
Obtaining the RAW data
57
+
class MoviesController {
46
58
59
+
function show($id)
60
+
{
61
+
// returns information of a movie
62
+
return Tmdb::getMoviesApi()->getMovie($id);
63
+
}
64
+
}
65
+
```
66
+
67
+
### Dependency injection example
47
68
```php
48
-
$client = Tmdb::getMoviesApi()->load(13);
69
+
use Tmdb\Repository\MovieRepository;
70
+
71
+
class MoviesController {
72
+
73
+
private $movies;
74
+
75
+
function __construct(MovieRepository $movies)
76
+
{
77
+
$this->movies = $movies;
78
+
}
79
+
80
+
function index()
81
+
{
82
+
// returns information of a movie
83
+
return $this->movies->getPopular();
84
+
}
85
+
}
86
+
```
87
+
88
+
### Listening to events
89
+
We can easily listen to events that are dispatched using the Laravel event dispatcher that we're familiar with.
90
+
The following example listens to any request that is made and logs a message.
In Laravel 5 instead of using the `Event` facade we could also have used the `EventServiceProvider` to register our event listener.
103
+
104
+
### Image helper
105
+
You can easily use the `ImageHelper` by using dependency injection. The following example shows how to show the poster image of the 20 most popular movies.
106
+
107
+
```php
108
+
namespace App\Http\Controllers;
109
+
110
+
use Tmdb\Helper\ImageHelper;
111
+
use Tmdb\Repository\MovieRepository;
112
+
113
+
class WelcomeController extends Controller {
114
+
115
+
private $movies;
116
+
private $helepr;
117
+
118
+
public function __construct(MovieRepository $movies, ImageHelper $helper)
119
+
{
120
+
$this->movies = $movies;
121
+
$this->helper = $helper;
122
+
}
123
+
124
+
/**
125
+
* Show the application welcome screen to the user.
0 commit comments