/** Muestra la vista de home
  *
  **/
 public function home()
 {
     /* obtiene de la tabla advertisements, los banner que han sido habilitados */
     $currentAds = Advertisement::where('enabled', '=', 'true')->get();
     /* obtiene de la tabla products, los productos que han sido habilitados */
     /* paginate(), indica que vamos a mostrar los productos de 6 en 6 */
     $availableProducts = Product::where('enabled', '=', 'true')->paginate(6);
     /* Indiciamos que el URL a usar para la paginación es home (se espera plazaapp/home/?page=1) */
     $availableProducts->setPath('home');
     /* retorna la vista de home con los banner y productos que previamiente fueron habilitados */
     return view('pages.home')->with(['currentAds' => $currentAds, 'availableProducts' => $availableProducts]);
 }
 public function deleteAd($id)
 {
     Advertisement::delete($id);
     $report = new Report();
 }
 /**
  * Borra un banner en específico, basado en su id
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     /* equivale a select * from advertisemets where id = $id */
     $advertisement = Advertisement::find($id);
     /* elimina la imagen asociada a dicho advertisement */
     \Storage::delete($advertisement->img_url);
     /* elimina la información del banner */
     $advertisement->delete();
     /* redirige al listado de banners */
     return redirect('advertisements');
 }
 /**
  * Borra un banner en específico, basado en su id
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     /* equivale a select * from advertisemets where id = $id */
     $advertisement = Advertisement::find($id);
     /* elimina la información del banner */
     $advertisement->delete();
     /* redirige al listado de banners */
     return redirect('advertisements');
 }
Example #5
0
<?php

use App\Advertisement;
Route::get('/', function () {
    return view('welcome');
});
Route::get('/advertise', function () {
    $ad = Advertisement::all()->random();
    return view('advertise.index')->with('ad', $ad);
});
Route::get('advertise/create', function () {
    return view('advertise.create');
});
Route::post('advertise/create', function () {
    $image = Input::file('image');
    $move = $image->move('images/advertisements', $image->getClientOriginalName());
    if ($move) {
        $create = Advertisement::create(['title' => Input::get('title'), 'image' => $image->getClientOriginalName(), 'description' => Input::get('description'), 'url' => Input::get('url')]);
        if ($create) {
            var_dump("created...");
        }
    }
});
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     //        return response()->json(Input::all());
     $ad = Advertisement::find($id);
     $productData = ['title' => Input::get('title'), 'price' => Input::get('price'), 'description' => Input::get('description'), 'brand' => Input::get('brand'), 'category_id' => Input::get('category_id')];
     $ad->product->update($productData);
     $adData = ['name' => Input::get('name'), 'pin' => Input::get('pin'), 'address' => Input::get('address'), 'state' => Input::get('state'), 'city' => Input::get('city'), 'phone' => Input::get('phone'), 'quantity' => Input::get('quantity')];
     $ad->update($adData);
     if ($ad->advertisable_type == 'App\\Motor') {
         $motorData = ['chassis_no' => Input::get('chassis_no'), 'model' => Input::get('model'), 'color' => Input::get('color'), 'doors' => Input::get('doors')];
         $ad->advertisable->update($motorData);
     }
     return response()->json('Updated');
 }