/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $transaction = Transaction::findOrFail($id); $accounts = Account::all()->where('user_id', Auth::user()->id)->lists('name', 'id'); $categories = Category::all()->where('user_id', Auth::user()->id)->lists('name', 'id'); $subcategories = Subcategory::all()->where('user_id', Auth::user()->id)->lists('name', 'id'); $entities = Entity::all()->where('user_id', Auth::user()->id)->lists('name', 'id'); return view('transactions.edit', compact('transaction'), array('accounts' => $accounts, 'categories' => $categories, 'subcategories' => $subcategories, 'entities' => $entities)); }
/** * Run the database seeds. * Crea 5 usuarios y por cada uno crea 2 categorias y 3 cuentas. * @return void */ public function run() { $faker = Faker\Factory::create(); for ($i = 0; $i < 10; $i++) { $user = User::create(array('email' => $faker->unique()->email, 'password' => '123456', 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'birthdate' => $faker->dateTimeBetween($startDate = '-24 years', $endDate = '-18 years')->format('Y-m-d'))); //categories for ($j = 0; $j < 2; $j++) { Category::create(array('name' => $faker->word, 'description' => $faker->text(100), 'user_id' => $user->id)); } //accounts Account::create(array('name' => 'Cash', 'starting_balance' => $faker->randomFloat(2), 'current_balance' => $faker->randomFloat(2), 'notes' => $faker->text(100), 'user_id' => $user->id)); Account::create(array('name' => 'Debit Card', 'starting_balance' => $faker->randomFloat(2), 'current_balance' => $faker->randomFloat(2), 'notes' => $faker->text(100), 'user_id' => $user->id)); Account::create(array('name' => 'Credit Card', 'starting_balance' => $faker->randomFloat(2), 'current_balance' => $faker->randomFloat(2), 'notes' => $faker->text(100), 'user_id' => $user->id)); } }
/** * Crea mi usuario administrador con 3 categorias y 3 cuentas. * * @return void */ public function run() { $faker = Faker\Factory::create(); $user = factory(vixit\User::class)->create(['id' => '1', 'email' => '*****@*****.**', 'password' => '1234', 'first_name' => 'Nery', 'last_name' => 'Brugnoni', 'birthdate' => '1992-09-24', 'type' => 'admin']); Category::create(array('name' => 'Alimentos', 'description' => $faker->text(100), 'user_id' => 1)); Category::create(array('name' => 'Vehículos', 'description' => $faker->text(100), 'user_id' => 1)); Category::create(array('name' => 'Mascotas', 'description' => $faker->text(100), 'user_id' => 1)); Subcategory::create(array('name' => 'Carnes', 'description' => $faker->text(100), 'category_id' => 1, 'user_id' => 1)); Subcategory::create(array('name' => 'Verduras', 'description' => $faker->text(100), 'category_id' => 1, 'user_id' => 1)); Subcategory::create(array('name' => 'Harinas', 'description' => $faker->text(100), 'category_id' => 1, 'user_id' => 1)); Account::create(array('name' => 'Efectivo', 'starting_balance' => 500, 'current_balance' => 500, 'notes' => $faker->text(100), 'user_id' => 1)); Account::create(array('name' => 'Tarjeta de Crédito', 'starting_balance' => $faker->randomFloat(2), 'current_balance' => $faker->randomFloat(2), 'notes' => $faker->text(100), 'user_id' => 1)); Account::create(array('name' => 'Tarjeta de Débito', 'starting_balance' => $faker->randomFloat(2), 'current_balance' => $faker->randomFloat(2), 'notes' => $faker->text(100), 'user_id' => 1)); Entity::create(array('name' => 'Supermercado xx', 'city' => 'Villa María', 'user_id' => 1)); Entity::create(array('name' => 'Panadería #1', 'city' => 'Villa María', 'user_id' => 1)); Entity::create(array('name' => 'Tienda NB', 'city' => 'Villa María', 'user_id' => 1)); }
public static function filterAndPaginate($name, $user_id) { return Category::name($name)->where('user_id', $user_id)->orderBy('id', 'ASC')->paginate(); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id, Request $request) { $category = Category::findOrFail($id); $category->delete(); $message = $category->name . ' was deleted successfully!'; if ($request->ajax()) { return response()->json(['id' => $category->id, 'message' => $message]); } Session::flash('message', $message); return redirect()->route('categories.index'); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $subcategory = Subcategory::findOrFail($id); $categories = Category::all()->where('user_id', Auth::user()->id)->lists('name', 'id'); return view('subcategories.edit', compact('subcategory'), array('categories' => $categories)); }